• 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

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.

Table of Contents

  • How to create bash/shell script for installing VirtualBox on Ubuntu 22.04 LTS Desktop
    • Create The Bash Script File.
    • Write The Bash Script For Installing VirtualBox.
    • Set Permission On Bash Script File
    • Execute Bash Script
  • FAQ
  • Conclusion

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

We expect you must have basic bash/shell knowledge to understand this script. The script is simple and self explanatory. If you have Linux Basic Command understanding also , this article is easy to follow.

Create The Bash Script File.

Open the terminal and use your file editor to create the bash script file. Here, we are using vim editor.

vim install_virtualbox_Ubuntu-22.04LTS.sh

Write The Bash Script For Installing VirtualBox.

#!/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

Set Permission On Bash Script File

Use the given below command to set the permission on your bash script.

Here, Permission structure is like this.

Owner = Full Permission (7)

Group = Read And Execute(5)

Other = No Permission (0)

chmod 750 install_virtualbox_Ubuntu-22.04LTS.sh

Execute Bash Script

./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.

FAQ

Why should I create bash script for installing VirtualBox

Using bash script for installing VirtualBox saves time because it is a single execution with no human intervention till installation get completed. Bash script learner should practice such small task in their routine to enhance their skills in bash scripting.

Conclusion

In this post we have learned how we can execute our VirtualBox installation work in less time and with less human intervention. The VirtualBox installation bash script is also a good example for bash script learners.

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. Create desktop launcher in Unity Desktop Ubuntu 16.04 LTS
  4. Xen Server License Nagios Plugin (bash script)
  5. Nagios plugin check_mailfromd bash script
  6. How to Use Expect In Bash Script
  7. How To Use case in Bash Script, Example
  8. How To Use opt In Bash Script
  9. Set and reset user password by bash script
  10. MySQL backup bash script

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

Primary Sidebar

Our Social Media Presence

  • Facebook
  • GitHub
  • Twitter

Linux Command

What is Linux Internal And External Command

Linux Basic Commands With Examples For Every Beginner

tr command to convert lines to space , tab and vertical tab

smbpasswd command not found on CentOS 7 and RHEL 7

Solution : semanage command not found

Unix / Linux : How to print duplicate lines from file

More Posts from this Category

You Might Like These Articles!

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

install java OpenJdk on Ubuntu

How to install Java (OpenJDK) on Ubuntu Linux

Always Useful Tips And Tricks

Install and optimize the png file by using optipng

How to zip the directory in linux with command line

How to protect from port scanning and smurf attack in Linux Server by iptables

How to change smtp port number 25 in postfix

fatal error: error writing to /tmp/ccwAjc9Z.s: No space left on device

send email after mysql backup through bash script in simple way

Nagios HTTP WARNING: HTTP/1.1 403 Forbidden

Explore 90+ Article On "Linux Tips And Tricks"

Copyright © 2023 ยท
The material in this site cannot be republished either online or offline, without our permission.
Proudly Blogging From Bharat.

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