• Skip to primary navigation
  • Skip to main content
  • Skip to primary sidebar
sharadchhetri

sharadchhetri

Tutorials On Linux, Unix & Open Source

  • Home
  • Linux Commands
  • Resources
    • Learn Linux
  • My WordPress plugins

Install VirtualBox On Ubuntu 22.04 LTS Desktop (Bash Script)

February 26, 2023 by Sharad Chhetri Leave a Comment

In this post, we will learn how to install VirtualBox on Ubuntu 22.04 LTS Desktop by using bash script. The reason for specifically writing VirtualBox on Ubuntu 22.04 LTS Desktop because we have tested this bash script in our personal DevOps laptop.

Being a DevOps Engineer, we should try to automate the things as much as possible. Either it is your personal laptop/PC or professional infrastructure setup, you must enjoy every chance of doing automation.
We created a simple bash script. If you are beginner in bash scripting, you will find some lines which will give some idea for example fetching Ubuntu Code Name in shell script.

VirtualBox is a virtualization software. We can create Virtual Machines by using VirtualBox. If you are a DevOps practitioner, we highly recommend to use the VirtualBox also. It has so well developed and mature. You can almost do so many practice/study on VirtualBox VM.
Anyway let’s see the bash/shell script for which you come for.

How to create bash/shell script for installing VirtualBox on Ubuntu 22.04 LTS Desktop

We expect you must a basic bash/shell knowledge to understand this script. The script is simple and self explanatory.

1. Create the bash file.

vim install_virtualbox_Ubuntu-22.04LTS.sh

2. Paste the given below contents in the bash script.

#!/bin/bash
# Author: Sharad Chhetri
# Date: 26-Feb-2023
# Description: This script will help to install the VirtualBox on Ubuntu 22.04 LTS Desktop

_wget_package="wget"
_os_codename=$(lsb_release -c|awk '{print $2}')
_package_name="virtualbox-7.0"

# Check if wget is installed or not. A good example for learner - how to use the if condition. 
if [ $(dpkg-query -W -f='${Status}' $_wget_package 2>/dev/null | grep -c "ok installed") -eq 0 ];
then
  sudo apt-get update -y && sudo apt-get install $_wget_package;
fi

#Update Apt Repo List
echo "deb [arch=amd64 signed-by=/usr/share/keyrings/oracle-virtualbox-2016.gpg] https://download.virtualbox.org/virtualbox/debian $_os_codename contrib" | sudo tee /etc/apt/sources.list.d/virtualbox.list

#Oracle Public Key
wget -O- https://www.virtualbox.org/download/oracle_vbox_2016.asc | sudo gpg --dearmor --yes --output /usr/share/keyrings/oracle-virtualbox-2016.gpg

#Install VirtualBox
sudo apt update -y
sudo apt install -y $_package_name

3. Set the permission on bash script file.

chmod 750 install_virtualbox_Ubuntu-22.04LTS.sh

4. Execute the script and see the result.

./install_virtualbox_Ubuntu-22.04LTS.sh

Once the script is successfully executed and completed, open the VirtualBox. If you are fairly new to Ubuntu then click to Activities>> Type VirtualBox in Search Box.now click on VirtualBox icon to open.

Share this:

  • Twitter
  • Facebook
  • More
  • Print
  • Email
  • LinkedIn
  • Reddit
  • Tumblr
  • Pinterest
  • Pocket
  • Telegram
  • WhatsApp
  • Mastodon

Related posts:

  1. How to install VirtualBox in Ubuntu 14.04 LTS (Trusty Tahr)
  2. Install VirtualBox on Ubuntu
  3. Xen Server License Nagios Plugin (bash script)
  4. Nagios plugin check_mailfromd bash script
  5. How to Use Expect In Bash Script
  6. How To Use case in Bash Script, Example
  7. How To Use opt In Bash Script
  8. Set and reset user password by bash script
  9. send email after mysql backup through bash script in simple way
  10. MySQL backup bash script

Filed Under: Linux Tagged With: ubuntu, ubuntu 22.04 lts, virtualbox

Reader Interactions

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Primary Sidebar

Our Social Media Presence

  • Facebook
  • GitHub
  • Twitter

Subscribe to Blog via Email

Enter your email address to subscribe to this blog and receive notifications of new posts by email.

Linux Commands

Linux : clear command and its keyboard shortcut

How to set root password on Ubuntu / Debian / Linux Mint

How to lock and unlock user account in linux

Useful tail command with examples in Linux/Unix

Install libjpegtran by using yum command in CentOS 6.x

sed command to display text between two strings or keywords

Linux Basic Commands For Every Beginner

Explore 70+ Articles On Linux Commands

Always Useful Tips And Tricks

Install and optimize the png file by using optipng

How to add/install Ubuntu fonts in CentOS/Red Hat Linux

configure: error: C++ compiler cannot create executables

Allow only members of Wheel group to use su command on RHEL/CentOS

master admin password openerp 7.x

How to install korn shell ksh in Linux

How to configure htdigest in nagios server

Explore 90+ Article On "Linux Tips And Tricks"

You Might Like These Articles!

Internal External Command

What is Linux/Unix Internal And External Command

simplecodesyntax wordpress plugin

SimpleCodeSyntax : My Another WordPress Plugin

Install Nginx

How To Install Nginx On Ubuntu 22.04 LTS

Install Latest Git package in Ubuntu Operating System

How To Always Install Latest Git Package In Ubuntu Operating System

libfuse

dlopen(): error loading libfuse.so.2 – Got Error On Ubuntu

Failed to open/create the internal network

VirtualBox Error: Failed to open/create the internal network

Copyright © 2023 ยท
The material in this site cannot be republished either online or offline, without our permission but Schools and Colleges can do in their Private Network
Proudly Blogging From Bharat.

  • Contact
  • About Me
  • My WordPress plugins
  • Privacy Policy