How to Install ROS on Ubuntu 18.04

How to Install ROS on Ubuntu 18.04

Hey ROS Developers!

In this post, we are going step-by-step to install ROS Melodic in a fresh Ubuntu 18.04. I’m using a regular desktop computer, the one I use to support me on ROS development.

Let’s do it!

Step 1 – Configuration

The first step is adding the ROS repository to your ubuntu sources.list

sudo sh -c 'echo "deb http://packages.ros.org/ros/ubuntu $(lsb_release -sc) main" > /etc/apt/sources.list.d/ros-latest.list'

Secondly, add the keys for accessing it:

sudo apt-key adv --keyserver 'hkp://keyserver.ubuntu.com:80' --recv-key C1CF6E31E6BADE8868B172B4F42ED6FBAB17C654
Executing: /tmp/apt-key-gpghome.WudTyznLyJ/gpg.1.sh --keyserver hkp://keyserver.ubuntu.com:80 --recv-key C1CF6E31E6BADE8868B172B4F42ED6FBAB17C654
gpg: key F42ED6FBAB17C654: public key "Open Robotics <info@osrfoundation.org>" imported
gpg: Total number processed: 1
gpg:               imported: 1

And finally, update your packages list:

sudo apt update
Hit:1 http://eu-west-1.ec2.archive.ubuntu.com/ubuntu bionic InRelease
Hit:2 http://eu-west-1.ec2.archive.ubuntu.com/ubuntu bionic-updates InRelease
Hit:3 http://eu-west-1.ec2.archive.ubuntu.com/ubuntu bionic-backports InRelease
Get:4 http://security.ubuntu.com/ubuntu bionic-security InRelease [88.7 kB]     
Get:5 http://packages.ros.org/ros/ubuntu bionic InRelease [4669 B]                              
Get:6 http://packages.ros.org/ros/ubuntu bionic/main amd64 Packages [569 kB]
Fetched 662 kB in 2s (406 kB/s)   
Reading package lists... Done
Building dependency tree       
Reading state information... Done
3 packages can be upgraded. Run 'apt list --upgradable' to see them.

 

Great!

 

Step 2 – ROS Installation

We have some options at this point. They are:

a. ROS Base

It installs ROS packagebuild and communication libraries.

It is recommended for embedded computers, where you don’t have much hardware for graphical tools or real robots (in the production stage) to run their specific tasks, without the need of debugging.

sudo apt install ros-melodic-ros-base

 

b. ROS Desktop

It installs ROS Base, rqt, rviz and robot-generic libraries

These are the basic packages for ROS development. It’s recommended for beginners to follow tutorials about ROS without having to install too much. RQT and RVIZ provides graphical interfaces for visualizing what is happening behind the scenes. With this option, you don’t have to work only using shell.

sudo apt install ros-melodic-desktop

 

c. ROS Desktop Full

It installs everything of ROS Desktop option plus 2D/3D simulators and 2D/3D perception.

If you want to simulate using ROS default Gazebo version, that’s your option. The Gazebo versions that comes with ROS Melodic is 9.0. (Related post: All about Gazebo 9)

sudo apt install ros-melodic-desktop-full

For convenience, I’m installing the ROS Base option, because I want to have a faster installation. After running the command, you must have a confirmation at the end of the output in your terminal:

0 upgraded, 485 newly installed, 0 to remove and 3 not upgraded.
Need to get 234 MB of archives.
After this operation, 1132 MB of additional disk space will be used.
Do you want to continue? [Y/n]

As you can see, ~1 GB will be installed.

Just press enter to confirm. It may take a while. A progress bar must be shown at the bottom:

Go and have a coffee =)

In the end, just a regular message about the last packages installed:

Setting up ros-melodic-nodelet-topic-tools (1.9.16-0bionic.20190601.015001) ...
Setting up ros-melodic-nodelet-core (1.9.16-0bionic.20190601.015433) ...
Setting up ros-melodic-roswtf (1.14.3-0bionic.20190601.014658) ...
Setting up ros-melodic-ros-comm (1.14.3-0bionic.20190601.015500) ...
Setting up ros-melodic-ros-core (1.4.1-0bionic.20190601.015718) ...
Setting up ros-melodic-ros-base (1.4.1-0bionic.20190808.193524) ...
Processing triggers for libgdk-pixbuf2.0-0:amd64 (2.36.11-2) ...
Processing triggers for libc-bin (2.27-3ubuntu1) ...

And you must have a free terminal ready to use again:

user@computer:~$

 

Step 3 – ROS Dependencies

We are almost there! ROS commands Client can also manage dependencies for you and rosdep is the one in charge of it.

That’s why we have to initialize rosdep. It goes like this:

sudo rosdep init
Wrote /etc/ros/rosdep/sources.list.d/20-default.list
Recommended: please run

	rosdep update

Similarly to ubuntu repositories, you need to update rosdep sometimes:

rosdep update
reading in sources list data from /etc/ros/rosdep/sources.list.d
Hit https://raw.githubusercontent.com/ros/rosdistro/master/rosdep/osx-homebrew.yaml
Hit https://raw.githubusercontent.com/ros/rosdistro/master/rosdep/base.yaml
Hit https://raw.githubusercontent.com/ros/rosdistro/master/rosdep/python.yaml
Hit https://raw.githubusercontent.com/ros/rosdistro/master/rosdep/ruby.yaml
Hit https://raw.githubusercontent.com/ros/rosdistro/master/releases/fuerte.yaml
Query rosdistro index https://raw.githubusercontent.com/ros/rosdistro/master/index-v4.yaml
Skip end-of-life distro "ardent"
Skip end-of-life distro "bouncy"
Add distro "crystal"
Add distro "dashing"
Add distro "eloquent"
Skip end-of-life distro "groovy"
Skip end-of-life distro "hydro"
Skip end-of-life distro "indigo"
Skip end-of-life distro "jade"
Add distro "kinetic"
Skip end-of-life distro "lunar"
Add distro "melodic"
Add distro "noetic"
updated cache in /home/ubuntu/.ros/rosdep/sources.cache

 

Step 4 – Configuring environment

We have ROS and the dependencies manager installed. Let’s configure our environment. This is a very important step, once we have it done, working with ROS will be smooth.

ROS is installed at /opt/ros/<distro> (in this case /opt/ros/melodic). In order to have ROS commands available, it’s needed to source the shell file inside of the installation folder. This is done like the following:

source /opt/ros/melodic/setup.bash

But.. considering we want to have it available in every terminal we open, we use to have a “shortcut”, which is adding this command to the file "/home/<user>/.bashrc". The .bashrc file is called every time a new terminal is opened, therefore, we won’t need to source ROS setup, since we have the instruction in this file. In order to add the command to the file, you can edit it manually using an editor of your preference or just execute the command below:

echo "source /opt/ros/melodic/setup.bash" >> ~/.bashrc

 

Step 5 – Testing it!

At this point, we must have everything in place. Let’s try some ROS commands to make sure the installation has finished successfully.

If you have the same terminal opened from the beginning, consequently, you have to execute the source for your .bashrc file to have ROS commands available.

source ~/.bashrc

And if you have added it to your .bashrc file, that’s the last time you will execute it =)

The first thing we should try it running roscore. In other words, we will run the process in charge of communicating everything ROS-related in a ROS environment.

roscore
... logging to /home/ubuntu/.ros/log/c70b2cce-e773-11e9-9f15-027a087bcd00/roslaunch-ip-172-31-31-24-15073.log
Checking log directory for disk usage. This may take awhile.
Press Ctrl-C to interrupt
Done checking log file disk usage. Usage is <1GB.

started roslaunch server http://ip-172-31-31-24:45551/
ros_comm version 1.14.3


SUMMARY
========

PARAMETERS
 * /rosdistro: melodic
 * /rosversion: 1.14.3

NODES

auto-starting new master
process[master]: started with pid [15096]
ROS_MASTER_URI=http://ip-172-31-31-24:11311/

setting /run_id to c70b2cce-e773-11e9-9f15-027a087bcd00
process[rosout-1]: started with pid [15107]
started core service [/rosout]

Your terminal must be stuck here, therefore, you can’t execute anything else while you have roscore process there. roscore is running and ready to serve to other ROS processes!

Open a new terminal (your .bashrc will do the necessary source) and execute:

rosnode list
/rosout

 

Step 6 – Conclusion

That’s it for today! You have ROS Melodic installed and ready to use!

If you like this kind of content, don’t forget to share it with your colleagues.

Either you like it or not, please leave a comment so we can keep improving our material!

 

*References:

Learning path

Intro to Robot Programming – ROS

The must-have learning path for Robot Operating System (ROS) & Robotics beginners.

Pin It on Pinterest