layout | title | license |
---|---|---|
default |
Introduction to lab environment and tools |
not needed |
The purpose of this lab is to introduce you to some package management tools for Ubuntu, to show you how to install Virtualbox on your system, and to get you to install an Ubuntu operating system from scratch, using Virtualbox. This will give you an environment that you can use safely in the lab, and also that you can install and use on your home PC, if you wish. The lab will involve the use of some commands with which you may not be familiar. At this stage, we'll just introduce enough to allow you to use the commands to achieve the goals of the lab. We'll revisit many of these commands in later weeks and explain them in more detail.
Before going any further, make sure that your machine is powered on and running the Ubuntu operating system.
The labs contain desktop PCs running a version of the Ubuntu operating system. The first steps in mastering your operating system are to become familiar with the tools for installing software and package management, so that you can install and remove software to configure the environment to suit your needs.
There are a number of tools in Ubuntu that support package management, including dpkg, apt, apt-get, aptitude, synaptic, and Ubuntu software center.
In this session we are going to use the command line tools dpkg
and apt-get
,
since they can be used to manage packages in both desktop and server environments.
We'll use them to set up our environment with the Virtualbox
tool that we'll be
using extensively in this module.
-
First, use
dpkg
to check that some standard packages are installed on your system, e.g.$ dpkg -l | grep gedit
This command will search through the names of all of the packages installed on your system and report any that contain
the work gedit
in them. It's an easy way to check whether or not gedit
is installed.
$ dpkg -l | grep gcc
This command does a similar job and allow us to check that we have a C compiler installed.
$ dpkg -l | grep make_nufc_champions_league_winners
This command also behaves the same as before, but this time comes up with no entries, since there is not yet any software package
that has this functionality and therefore it cannot be installed.
Now check whether or not Virtualbox
is already installed on your system.
$ dpkg -l | grep virtualbox
If there is an entry for virtualbox-5.2
then Virtualbox
is already installed and you can skip to Using Virtualbox
.
-
To install software packages from the command line, use
apt-get
, which will download the required package and any dependencies from the software repositories that it knows about, and install it for you. The list of software repositories is maintained mainly in a file,/etc/apt/sources.list
, but also in a set of smaller files, contained in the directory/etc/apt/sources.list.d
. Use theless
andls
commands to have a look at the known repositories:$ less /etc/apt/sources.list
Use the space bar to page through the list and press q
when you want to stop.
$ ls /etc/apt/sources.list.d
We'll create a new file in /etc/apt/sources.list.d
to hold a reference to our Virtualbox
repository. You can use any text editor
with which you are familiar to do this. You'll need to start the editor as the superuser
since you'll be writing to a directory that
is protected against modification by general users. The most useful editors to use from the command line are vim
and nano
. Here's an
example of what you should do using nano
.
$ sudo nano /etc/apt/sources.list.d/virtualbox.list
Now copy and paste the line below into your new file. Note that this is the correct repository for use on Ubuntu 16.04. If you
have a different version of Ubuntu, you will need to change xenial
to match your distribution name, e.g. trusty
for 14.04.
deb http://download.virtualbox.org/virtualbox/debian xenial contrib
-
Add the Oracle public keys for apt-secure. These are used in checking that the downloads really are from Oracle.
$ wget -q https://www.virtualbox.org/download/oracle_vbox_2016.asc -O- | sudo apt-key add - $ wget -q https://www.virtualbox.org/download/oracle_vbox.asc -O- | sudo apt-key add -
-
Before you can install
Virtualbox
, you will need to synchronise the package index files from their sources, as follows:$ sudo apt-get update
Then you can install Virtualbox
, using the command
$ sudo apt-get install virtualbox-5.2
This is quite a large package and installation may take a few minutes. When the installation completes, you can start Virtualbox
from the command line,
as follows:
$ virtualbox &
You should see a window that looks like the one below.
Note there is further guidance for downloading Virtualbox at https://www.virtualbox.org/wiki/Linux_Downloads.
We'll begin by installing a version of Ubuntu Server. We'll be able to do most of the lab work for this module on this system. It is significantly smaller than the desktop version. We'll use a variety of systems during the module but this will be the primary one.
Ubuntu is distributed from the Ubuntu website using DVD images that are provided in the form of .iso files. We are going to use Ubuntu Server 16.04.5. You can download the iso image using the following commands:
$ cd ~/Downloads
$ curl -L -O -J http://releases.ubuntu.com/16.04/ubuntu-16.04.5-server-amd64.iso
The file is about 870M in size and so will take a few minutes to download.
- Select
New
in theVirtualbox Machine Manager
(VMM) window. Give your machine a name, as below.
- Click
Next
. Continue to accept the default options until your new virtual machine (VM) has been created. You should have a window that looks like the one below.
- Select the VM and click
Start
. Select icon with the green upward arrow and browse to the location of your .iso image file. Select the image file and the OS will begin its installation procedure, just as it would on a 'real' machine.
Congratulations!!! You have just completed a full install of an Ubuntu Server operating system.
-
Before going further, it's a good idea to update the packages on your new server, as follows:
$ sudo apt-get update $ sudo apt-get upgrade
-
You've going to need a C compiler and the Ubuntu server doesn't have one yet. Time to install one.
$ sudo apt-get install gcc
-
Although we used the
nano
editor earlier in this lab, there are many good editors available for Unix/Linux. One powerful editor that is always likely to be available on your system, whether desktop or server, isvim
. It's an 'old-school' editor but still the editor of choice for DevOps and Sys admins. In other words, if you need to look after an operating system, it's a good idea to know how to usevim
, at least for basic editing tasks. The source code of this web page was written usingvim
.vim
is a modal editor and, as such, is different from any editor that you've used before. Start by working through thevimtutor
. It should take you about 30 minutes.$ vimtutor
-
Now check your understanding of
vim
and your C compiler by writing and executing the traditionalhelloworld
program. Usevim
to enter the text below.#include <stdio.h> int main() { printf("Hello world\n"); return 0; }
Save the file as helloworld.c
, then compile and run it.
$ gcc -o helloworld helloworld.c
$ ./helloworld
-
When you're ready to shut down your system, you can do this from the command line using the
shutdown
command.$ sudo shutdown -h now
- Work through the tutorial at http://hesabu.net/unixtut.
- Work through the sections of Learning the Shell from 1. What is "The Shell"? through to 9. Permissions. Don't just read passively. Have a command line open and try everything. Experiment until you are comfortable with these ideas.
- Develop your understanding further by reading Chapters 1-6 in The Linux Command Line. Have a command line open and try out what you're reading about.
The main advantage for you in this module of knowing how to use Virtualbox
is that you can create an Ubuntu
system that will run on your home PC. This means that you'll be able to carry on working and exploring the
operating system when you're not in a University lab.
-
If you decide that you would like to be able to run an Ubuntu system on your Windows or Mac machine, visit the virtualbox home page. Download the installtion program for your system and install
Virtualbox
on your machine. -
Now work through the section above,
Using Virtualbox
, again, on your new system. -
If you're feeling adventurous, you could also download and install an Ubuntu desktop operating system for use at home. If you want an environment that is just the same as the lab environment, you should download Ubuntu 16.04.5 Xenial Xerus. If you have a 64-bit Windows machine you should download http://releases.ubuntu.com/16.04/ubuntu-16.04.5-desktop-amd64.iso. If you have a different machine, you should check the Ubuntu website for guidance about which image to download. Once you have download the image, you may find the installation instructions useful. See also the official Ubuntu documentation.
-
You can develop your
vim
skills further by using the resources at Learning Vim for Beginners.