There are a few methods available to install ROS. You can do it directly using repositories, the way we will do now, or you can use the code files and compile it. It is more secure to do it using repositories because you have the certainty that it will work.
In this section, you will see the steps to install ROS Electric on your computer. The installation process has been explained in detail in the official ROS page: http://wiki.ros.org/electric/Installation.
We assume that you know what an Ubuntu repository is and how to manage it. If you have any queries, check the following link to get more information: https://help.ubuntu.com/community/Repositories/Ubuntu.
Before starting with the installation, we need to configure our repositories. To do this, the repositories need to allow restricted, universal, and multiversal repositories. To check whether your version of Ubuntu accepts these repositories, click on Ubuntu Software Center in the menu on the left of your desktop.
Navigate to Edit | Software Sources and you will see the following window on your screen. Make sure that everything is selected as shown in the following screenshot:
Normally, these options are marked, so you will not have problems with this step.
In this step, you have to select your Ubuntu version. It is possible to install ROS Electric in various versions of the operating system. You can use any of them, but we recommend you to always use the most updated version to avoid problems:
A specific way to install the repositories for an Ubuntu-based distro such as Ubuntu Lucid Lynx (10.04) is as follows:
$ sudo sh -c 'echo "deb http://packages.ros.org/ros/ubuntu lucid main" > /etc/apt/sources.list.d/ros-latest.list'
A generic way for installing any distro of Ubuntu relies on the
lsb_release
command that is supported on all Linux Debian-based distro:$ sudo sh -c 'echo "deb http://packages.ros.org/ros/ubuntu `lsb_release -cs` main" > /etc/apt/sources.list.d/ros-latest.list'
Once you have added the correct repository, your operating system knows where to download the programs that need to be installed on your system.
This step is to confirm that the origin of the code is correct, and nobody has modified the code or programs without the knowledge of the owner. Normally, when you add a new repository, you have to add the keys of that repository so that it is added to your system's trusted list:
$ wget http://packages.ros.org/ros.key -O - | sudo apt-key add –
We can now be sure that the code came from an authorized site.
Now we are ready to start the installation. Before we start, it would be better to update the software to avoid problems with libraries or the wrong software version. We do this with the following command:
$ sudo apt-get update
ROS is huge; sometimes you will install libraries and programs that you will never use. Normally, it has four different installations depending on the final use; for example, if you are an advanced user, you may only need basic installation for a robot without enough space in the hard disk. For this book, we recommend the use of full installation because it will install everything that's necessary to make the examples and tutorials work.
Don't worry if you don't know what you are installing right now, be it rviz, simulators, or navigation. You will learn everything in the upcoming chapters:
The easiest (and recommended if you have enough hard disk space) installation is known as desktop-full. It comes with ROS, the Rx tools, the rviz visualizer (for 3D), many generic robot libraries, the simulator in 2D (such as stage) and 3D (usually Gazebo), the navigation stack (to move, localize, do mapping, and control arms), and also perception libraries using vision, lasers or RGB-D cameras:
$ sudo apt-get install ros-electric-desktop-full
If you do not have enough disk space, or you prefer to install only a few stacks, first install only the desktop installation file, which comes only with ROS, the Rx tools, rviz, and generic robot libraries. Later, you can install the rest of the stacks when you need them (using aptitude and looking for the
ros-electric-*
stacks, for example):$ sudo apt-get install ros-electric-desktop
If you only want the bare bones, install ROS-base, which is usually recommended for the robot itself or computers without a screen or just a TTY. It will install the ROS package with the build and communication libraries and no GUI tools at all:
$ sudo apt-get install ros-electric-ros-base
Finally, along with whatever option you choose from this list, you can install individual/specific ROS stacks (for a given stack name):
$ sudo apt-get install ros-electric-STACK
Congratulations! You are in this step because you have an installed version of ROS on your system. To start using it, the system must know where the executable or binary files as well as other commands are. To do this, you need to execute the next script. If you install another ROS distro in addition to your existing version, you can work with both by calling the script of the one you need every time, since this script simply sets your environment. Here, we will use the one for ROS Electric, but just change electric
to fuerte
or groovy
in the following command if you want to try other distros:
$ source /opt/ros/electric/setup.bash
If you type
roscore
in the shell, you will see that something is starting. This is the best test to find out whether you have ROS and whether it is installed correctly.
Note that if you open another shell and type roscore
or any other ROS command, it does not work. This is because it is necessary to execute the script again to configure the global variables and path for the location where ROS is installed.
It is very easy to solve this. You only need to add the script at the end of your .bashrc
file and when you start a new shell, the script will execute and you will have the environment configured. Use the following command to do this:
$ echo "source /opt/ros/electric/setup.bash" >> ~/.bashrc $ source ~/.bashrc
If it happens that you have more than a single ROS distribution installed on your system, your ~/.bashrc
file must source only setup.bash
of the version you are currently using. This is because the last call will override the environment set of the others, as we have mentioned previously, to have several distros living in the same system and switch among them.