How to Install ROS on Ubuntu 18.04

How to Install ROS on Ubuntu 18.04 by The Construct

Written by Marco Arruda

09/10/2019

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.

Masterclass 2023 batch2 blog banner

Check Out These Related Posts

20 Comments

  1. Avrishka

    Great tutorial, all code ran had the predicted outputs!

    Reply
  2. Ed S.

    No problems getting this installed with the end result as indicated.

    It would be great to include a couple links to suggested next steps / things to try.

    Reply
  3. kailuo

    About Marco Arruda teacher:
    Thank you! I’m a beginner. I’ve been learning for a long time, and I’ve only been learning from you. There’s something wrong with me. But there’s a way of getting started. I have to learn more from you. Thank you.

    Reply
  4. kailuo

    Hello:

    Thank you. I admire your great knowledge. I’m a beginner. There is still a lot of knowledge not to understand. Will consult you. Thank you.

    Reply
  5. Ayhan

    Very very thanks. This article worked very well. I learned a lot. (From Turkey 🙂 )

    Reply
  6. kailuo

    The knowledge of this website is too rich. I want to learn from you. Please contact frequently. Thank you.

    Reply
  7. bigkings

    Great tutorial. It was helpful. How do I use the newly installed ROS with Gazebo9?

    Reply
  8. Treath

    Very clear instructions and clean code. Great job!

    Reply
  9. kailuo

    Learn from you.Knowledge is really too sophisticated.Thank you very much!

    Reply
  10. Ahmed

    Grateful tutorial ….thank you so much !

    Reply
  11. kailuo

    Teacher Marco Aruda Hello: I have something to ask. I can connect to the network after installing the UBUNTU18.04, but I can’t connect to the wireless network, I do n’ t know how to do it, and I search the Internet a lot without finding the result. Ask the teacher to help. Thank you!

    Reply
  12. emrehan

    Thank you very much it helps me a lot

    Reply
  13. Muhammed ZEYN

    when I tried to init rosdep it said that it is not found so I had to install it with the command
    sudo apt install python-rosdep2
    then I could finiish the process , for anybody who had the same problem that is the solution

    Reply
    • Jaime

      i had the same problem than you. Thank you for your comment.

      Reply
  14. Anonymous

    I got this error when running roscore command .Can someone help me out please
    Traceback (most recent call last):
    File “/opt/ros/melodic/lib/python2.7/dist-packages/roslaunch/__init__.py”, line 277, in main
    write_pid_file(options.pid_fn, options.core, options.port)
    File “/opt/ros/melodic/lib/python2.7/dist-packages/roslaunch/__init__.py”, line 111, in write_pid_file
    with open(pid_fn, “w”) as f:
    IOError: [Errno 13] Permission denied: ‘/home/deoth/.ros/roscore-11311.pid’

    Reply
  15. Khoukou

    How about kinetic for Ubuntu 20.04?

    Reply
  16. Betty Ann

    Thank you for the listing on your web page. You have a good looking web site.
    This website helpfull to me .

    Reply
  17. Vardyansyah

    excuse me, i have the problem when i install python-roslaunch, they said

    Reading package lists… Done
    Building dependency tree
    Reading state information… Done
    Some packages could not be installed. This may mean that you have
    requested an impossible situation or if you are using the unstable
    distribution that some required packages have not yet been created
    or been moved out of Incoming.
    The following information may help to resolve the situation:

    The following packages have unmet dependencies:
    python-roslaunch : Depends: python-roslib but it is not going to be installed
    E: Unable to correct problems, you have held broken packages.

    i was tried to solve this problem according this link https://answers.ros.org/question/260796/roslaunch-reinstallation/, but nothing happened and my environment was installed correctly. can anyone help me? Thanks..

    Reply
  18. Vipin P

    What should be the minimum system requirement needed for ROS Melodic

    Reply
  19. RAFIK

    thanks a lot this helped me so much

    I just had a problem in stage 3
    I had to put this command: ”sudo apt-get install python-rosdep” to install ROS dependence before initialize it

    sudo apt-get install python-rosdep

    then

    sudo rosdep init

    and thanks again for helping me

    Reply

Submit a Comment

Your email address will not be published.

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Pin It on Pinterest

Share This