Skip to content

Instantly share code, notes, and snippets.

@mshafae
Last active August 6, 2022 18:49
Show Gist options
  • Save mshafae/541686de0f94d1167fbbc6e057c4cdb9 to your computer and use it in GitHub Desktop.
Save mshafae/541686de0f94d1167fbbc6e057c4cdb9 to your computer and use it in GitHub Desktop.
Script to install Virtualbox on Ubuntu
#!/bin/bash
# In case you want to install from a the Oracle package repository.
oracle_install ( ){
CODENAME=`lsb_release -c | cut -f 2`
eval sudo sh -c 'echo "deb https://download.virtualbox.org/virtualbox/debian ${CODENAME} contrib" >> /etc/apt/sources.list'
wget -q https://www.virtualbox.org/download/oracle_vbox_2016.asc -O- | sudo apt-key add -
sudo apt-get update && sudo apt-get install virtualbox-6.0
}
#
# Main
#
if (( EUID == 0 )); then
echo "error: do not this script as root"
exit 1
fi
dpkg --get-selections | grep install | grep "virtualbox-" > /dev/null 2>&1
if [ $? -eq 0 ]; then
echo "Virtualbox is already installed"
VB=`dpkg --get-selections | grep install | grep "virtualbox-" | awk '{print $1}'`
echo "Removing ${VB} first."
sudo apt-get remove ${VB} && sudo apt-get purge ${VB}
fi
sudo apt-get update
P=`apt-cache search virtualbox-5.2 | cut -f 1 -d\ `
if [ ${P}"x" = "x" ]; then
P=`apt-cache search virtualbox-6.0 | cut -f 1 -d\ `
fi
if [ ${P}"x" = "x" ]; then
P=`apt-cache search virtualbox | grep "^virtualbox " | cut -f 1 -d\ `
fi
if [ ${P}"x" = "x" ]; then
echo "There is a problem identifying a package to install."
echo "Contact your instructor."
exit 1
fi
echo "Installing ${P}"
sudo apt-get install -y ${P}
echo "For virtualbox to work, make sure:"
echo " - secure boot is disabled in the BIOS"
echo " - VT-X or AMD-V extensions are enabled"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment