Intro: Getting Started With Ubuntu Linux
Linux has been the operating system (OS) of choice for the computer savvy since its inception, but in the past couple of years with the release of small linux based physical computing platforms such as the Raspberry Pi, BeagleBone, and Arduino Yun (among many others), there has been an explosion of interest in the OS. To be sure, there is definitely no shortage of tutorials and resources for learning Linux, but I wanted to create a basic introduction taylor made for the Maker community and designed to get anyone started with Linux (Ubuntu) regardless of their current OS, or computing know-how.
As a researcher in the field of robotics I use Linux exclusively at work and there are a lot of reasons why, but here are 3 good ones...
- FREE. Linux OS's are, for all intents and purposes,free. When I first read that I said to myself, "Big deal, I obviously already have an OS or else I wouldn't be reading about Linux on this computer". While this was true, when I started needing more powerful computing platforms than the Arduino Uno, I realized that I didn't want to shell out $100 for Windows for every computer dedicated to a project. In robotics it is not uncommon for a single robot to have multiple computers on-board tackling different tasks - not having to buy (and maintain) paid OS's is a godsend in these cases. More generally speaking, as your projects grow in complexity, so too will your need for computing power and when you do jump from microcontrollers to full blown computers you will be happy to have Linux.
- SIMPLE. While most Linux varieties provide Graphic User Interfaces (GUIs) to simplify the day to day experience, they are decidedly transparent compared to Windows or Mac. This just means that you have much more direct access to the basic functionality of the OS rather than it being hidden behind layers of user interfaces and preferences. This comes in handy when you need to do things like access GPIO pins on your BeagleBone.
- CONTROL. By default you are the master of your domain. In Linux (using administrator privileges) you have total control over the system and can do as you please with it. This comes with its pitfalls, such as deleting your entire hard disk with a single line of commands, but with a bit of caution this is a powerful tool.
In addition to these reasons, Linux is a developer's platform and coding is generally much less painful. You will also find a lot of support on the web for any and all fathomable questions.
So without any further proselytizing, lets get started using Linux!
Step 1: Getting Set Up: Downloads
For the rest of this tutorial we will be using the Linux OS, Ubuntu. Ubuntu is one of the most popular distributions/versions/flavors of Linux but it is by no means the only one. One nice aspect about Ubuntu is that it is not much of a departure from Windows or Mac OS's and therefore is a bit easier to learn than some of the other more "hardcore" Linux distributions (a.k.a. distros). Having said this, once you get comfortable with the workflow in Ubuntu you should experiment with the other distros out there.
There are 3 basic methods of installing Ubuntu on your machine:
- Full replacement. The old OS is wiped clean, along with its data and all your cat videos, and Ubuntu is installed just like any old OS. If you are confident that you wish to switch this choice is very simple, just follow the steps on the Ubuntu website.
- Partitioning. This is where you split your hard drive into two or more parts (partitions), keeping your current OS intact in a main partition, and installing Ubuntu on a separate partition alongside. Depending on your main OS this can be as simple as a few mouse clicks or as complex as modifying your grub boot loader. My home computer is a Mac and while I managed to install Ubuntu on a partition it took more time than I would have liked, and I ultimately deleted it because Apple updates kept "fixing" my startup scripts... Despite my troubles this is a very popular option and I would recommend looking online for OS specific tutorials.
- Virtual Machine. This is the method we will follow in the tutorial. Basically, using a very nifty tool you can install "virtual computers" on your computer which operate inside a window on top of your current OS. This is the easiest, most fool-proof option of the three. One downside to a virtual machine is that it will run much slower than a regular install, but if you are just getting started, it is a great (and safe) way to get into Ubuntu.
The Virtual Machine (VM) program we will use is called VirtualBox from Oracle. This is a free application that allows you to install any number of OS's on top of your main OS without having to worry about many of the technical details involved. Navigate to their downloads page (link here) and select the version suited for your current OS. Once it is downloaded follow the installation wizard and then lets go get us some Ubuntu!
As of the writing of this instructable the newest supported release of Ubuntu, 14.04, is NOT compatible with VirtualBox. I imagine that this will be resolved in the near future but for now we will install the previous (but still awesome) release, 13.04. Go to the Ubuntu website and navigate to their alternative downloads page (link here). Scroll down to the BitTorrent section and it should look something like the picture above.
Click the link labeled "Ubuntu 12.04.4 Desktop (64-bit)" and this should open up a bittorrent download.
Never downloaded via Peer-to-Peer clients? This instructable should get you going.
Once the .iso file has finished downloading, copy and paste it into a directory (folder) somewhere where it will be safe - maybe a directory called "Virtual Machine Isos" or something along those lines.
Step 2: Getting Set Up: Install (1/3)
Now it is time to install our VM.
- Open up VirtualBox and the welcome dialog should appear.
- In the top left of the window click the blue circle/star thingy labeled, "New".
- A new window will appear, here you should name the VM, select the type as "Linux", and the version to "(Ubuntu 64 bit)". The name you choose doesn't really matter but it should be clear. Click "Continue".
- Now select the amount of memory (RAM) you want to dedicate to the machine while it is running. This setting is not too important for the basic user but in short, the more RAM you give to the VM the faster it will be at the cost of slowing down your normal OS. No worries though because, when you turn off the VM your normal OS will have all the memory returned to it. Luckily VM has a nice little color guide for selecting the amount of memory you should allocate, so as long as you are above the minimum and below the orange you should be fine. I chose 4 Gigs of RAM. Click "Continue".
- In the next window select "Create a virtual hard drive now" then click "Create".
- Following this, select the "VDI (VirtualBox Disk Image)" option and click "Continue".
- In the next window you are asked to select the type of memory allocation. "Dynamically Allocated" means that the amount of hard disk your VM uses will grow or shrink depending on how much stuff you install in it. "Fixed Size" means that the VM will immediately suck up a certain amount of memory regardless of the actual size of your VM. If you have a small hard drive I suggest Dynamic Allocation because it is more memory thrifty. If you are on a computer with memory to spare (+500 Gigs), go with Fixed Size because it is faster. I choose Dynamic Allocation. Click "Continue".
- Now we select the amount of memory (the size of our virtual hard drive) we wish to give to the VM. REMEMBER, this memory will no longer be available to the host OS once the VM starts filling the memory up. I picked 25 Gigs for my VM. Finally click "Create".
You should be greeted by a window summarizing the system you just created. Now lets get Ubuntu running...
Step 3: Getting Set Up: Install (2/3)
Remember that .iso file we downloaded... we now need to point the VM to it.
- At the top left of the system overview window, click the yellow gear symbol labeled, "Settings".
- In the Settings pop-up click to "Storage" tab.
- On the left in the "Storage Tree" list you will see an item labeled, "Controller: IDE". To the right of this there should be what looks like a tiny CD with a green plus (+) sign on it. Click this symbol.
- A dialog box will open, select the "Choose Disk" option.
- Now browse through your files and find the Ubuntu .iso you saved earlier. Highlight the .iso file and click OK.
- Your system is now ready to go, just click the green arrow labeled, "Run" (next to the yellow gear symbol), and your machine will begin booting up.
Step 4: Getting Set Up: Install (3/3)
You should now be seeing the standard Ubuntu setup window. Select your language and click "Install Ubuntu". At this point you simply need to follow the very well done setup wizard and let the install do its thing. There are only two potential trouble spots to which may trip you up...
1. When prompted with the screen in the second image, make sure to check the two boxes "Download updates while installing" and "Install 3rd party software". These options will usually install the hardware drivers to make ubuntu compatible with your computer's peripheral devices.
2. When you reach the screen in the third image select "Erase disk and install Ubuntu". Have no fear this will not wipe out your hard drive. Ubuntu only sees the virtual hard drive you created and will not interact with your "real" hard drive - so if you do anything totally crazy you can simply delete and recreate the VM, no harm no foul.
The rest of the options are very straightforward and should cause no second guessing.
Ubuntu will then proceed to install itself into the VM and this can take anywhere from 20-40 minutes depending on you computer. Once the installation is done you may have to restart but you should be met with the Ubuntu desktop. Now the fun can begin...
Step 5: Ubuntu Basics - Software Installation
Looking at the image above you will notice that the interface of Ubuntu is very similar to that of Mac or Windows. Play around with the interface to get a feel for where things are.
When I first got started with Linux one of the big mysteries for me was how to install programs. This may seem like a trivial issue but for me it took a lot of trial and error to figure out the lay of the land. In Windows or Mac the most common method of installation is to download some kind of .exe or .dmg file and run it. While there are other ways of installing programs this one is largely predominant. In Ubuntu there are 4 major ways of getting software and I will list them in descending order of simplicity.
- Via the Software Center. In the Ubuntu Software Center you can browse and install a wide array of free and paid programs much as you would in the Mac App Center (I don't know a great analog for Microsoft). You simply need to click the install button and Ubuntu takes care of the rest. Once the program is installed you will see its icon pop up in the launcher bar on the left.
NOTE: Right click launcher bar icons for options on either hiding or locking them to the bar much like the Task Bar in Windows or the Application Bar in Mac.
- By downloading packages online. Sometime a program is not availible directly in the software center and you have to go to a website to download it. When you select the download for Linux, more often than not, the file you download will be a "Debian Package" (.deb).
Programs in Linux are commonly referred to as "Packages" there is some minutia here but this definition is sufficient for the tutorial.
Once you download the package file you can double click on it and the software center will open up and show you an option to install the package. Go ahead and click install and you are on your merry way! Google chrome is a good example here.
- Using package managers. Ubuntu comes with three primary package managers built right in: apt-get, synaptic and aptitude. These are all used from the command line which we will go over in the next step. For now I will just detail apt-get but know that the other two managers are also very useful. apt-get allows you to access a repository of packages to search for, install and maintain software on your computer. To use apt-get we write the following in a terminal window: sudo apt-get install package name.
sudo - use administrator rights (you will be prompted for a password).
apt-get - the package manager
install - download, build and install the program (the full shebang)
package name - just type the exact name of the package no quotes, italics, nada.
An example might be: sudo apt-get install libopencv-dev. This will install the OpenCV libraries on your system to do cool computer vision stuff! For those of you who have tried to install OpenCV on other platforms, you should be crying with the simplicity of installation in Ubuntu.
- Building from source. What does this mean? Building from source means that you download the source code files, for example the .cpp and .hpp files for a C++ program, you compile the files using a Make program, and you install the libraries generated. If this all seems like gibberish don't sweat it you will learn young jedi! At least now you won't be totally lost when you see someone on stackoverflow says "build from source".
So why spend so much time talking about installing programs...? Well when you have spent all of your life in either Windows or Mac and haven't done too much/any coding, the concept of installing a program in Linux may seem a little backwards, but in fact it is just because most OS's pull a veil of user interface over your head. In all reality when you install a program on your PC or Mac, your are really following the last two steps of the build from source method. Some programmers have written millions of lines of code and "prepared" it for a specific operating system, then when you go to install the latest version of Microsoft Word, the little wizard takes care of installing the libraries and setting up the interfaces. So really the only thing different is you... You now understand what is really going on in your computer in the background when you install a new program - and all that just from trying to play with Ubuntu!
One final note on installations,
If you want to search for a package to install via apt-get but you dont know the exact name of the package, you can use apt-cache search *part of the package name*. The asterisks around the package name are known as "Wildcard" operators, and essentially say look for "part of package name" with anything around it. Example: *opencv*.
Step 6: Ubuntu Basics - Terminal
One of the biggest differences between Linux and other OS's is the importance of the Terminal (or Command Line). In both Windows and Mac you can easily access a similar program but it is fairly rare for the average user. In Linux/Ubuntu the Terminal is your best friend. To open terminal you can click the icon at the top of the application bar and type "terminal" in the window (as in the first screenshot) and this will open a terminal window. Alternatively, you can use the default hotkey combination: ctrl+alt+T. From the terminal you can do anything and everything and you will be surprised at how efficient you will get with it, but when you start out you will more likely want to pull out your own hair.
The terminal works by giving some sort of command followed by arguments. We have already seen an example of this in the installation step where we used sudo apt-get install package.sudo is just telling the terminal the you are the boss and it should do whatever you say. The command in this example is apt-get, which tells the computer to start the apt-get application which manages your packages. install indicates to the apt-get application that you would like to download, build, compile and install (not just download for instance) some program. Finally the final argument is the package name package, which directs apt-get to the right place for the software.
More day to day terminal activities may involve basic directory management - a.k.a. making, copying, deleting, renaming, etc. directories and files. While you can do all of these tasks easily from the Documents GUI, working with the terminal will help you remember the various commands. Let's have some examples (what you type is in bold):
- Open terminal and type the following commands to see what happens. By default when you open terminal you are in your Home folder denoted ~/.
- ls - Lists the contents of the current directory
- pwd - prints the path of the current directory
- cd/path/to/new/dir- Change Directory, use this to move between folders. (cd ..) moves you up one directory and (cd) by itself will send you back to your home folder no matter where you are.
- mkdir nameOfNewDir - create a new directory
- cp something someplace - copy something to someplace
- mv - move something, same syntax as cp
- rm filename - remove a file PERMANENTLY (may need sudo before rm if the file is protected)
- rm -rf directoryName - remove a directory and all its contents
!!! -rf is dangerous use with caution !!!
- gedit newTextFileName- create and open a blank text file in the native Ubuntu text editor gedit
- pico newTextFileName - create and open a blank text file in a terminal based text editor (useful for quick changes)
- echo - this one is a bit odd but basically it displays a line of text
...and the list goes on. Check out this website for a more comprehensive one.
Terminal is a powerful tool but it may take a while before you realize it. Play around with these commands and MAKE mistakes! No one ever really learns anything till they fail at it first. When you get error messages search for them online. When you don't know how to do something... search for it online. More or less, the answers you seek are out there you just have to ask the right questions.
To finish of this tutorial lets get Ubuntu up to date.
- Open Terminal
- sudo apt-get upgrade
- Type your password.
- Answer "yes" if/when prompted.
Step 7: Conclusion and Next Steps
To shutdown your VM Ubuntu, click the symbol in the top right of the desktop (little gear with a vertical bar) and scroll down to "shut down". Click "Shut Down" when prompted. Your VM window will close and your Ubuntu session has been closed - relinquishing all the RAM resources back to your host OS.
Although this was a very brief introduction to Ubuntu and Linux, I hope to have at the very least demystified some of its minor idiosyncrasies, and while I am sure that my explanations/simplifications will make some cringe, I think it is important to present these basic concepts in a relatively global context.
Where to go from here?
You now have a functioning Ubuntu system and can start experimenting with of it. One reason Ubuntu is so popular is that it is very developer friendly, so try coding something! I will be posting some code based instructables in the near future but in the meantime try compiling some C++ or running some Python scripts. Why not try out some OpenCV examples since you now have it installed?! If you're serious about robotics, Ubuntu is the only officially fully supported platform for the Robot Operating System (ROS). We will get into this in a later tutorial but go check out their website and tutorials in the interim.
Despite their practicality for getting started out, VMs are relatively limited over the long haul. If you find yourself using Ubuntu more and more I would highly recommend installing it on a partition or a dedicated computer to harness its full awesomeness.
I hope you enjoyed this instructable and will build on these foundations in the instructables to come.