Categories
ROS

How to Install ROS Melodic on Ubuntu 18.04

It’s easy to install ROS Melodic on Ubuntu 18.04. Specifically, you will learn how to install the official ROS repo, add the official ROS keyring to get authentic ROS Melodic packages, and set up ROS environment in terminal, all on your Ubuntu 18.04 machine.

ROS Melodic & Ubuntu 18.04

Robot Operating System (ROS) is the most popular framework to program robots. Yes, ROS is not a traditional operating system per say. But it does have communication between the robot hardware and your robot program. It is so popular that there are more than 50% of the robots in the world using this framework.

ROS Melodic Morenia, is primarily targeted to Ubuntu 18.04, which is why we have this installation tutorial on 18.04. This means other Ubuntu versions are not supported such as 16.04. It is released on May 23rd, 2018 and is a Long-Term Support (LTS) version, which is also the case for Ubuntu 18.04. They are both supported for 5-year period until May 2023. This installation support 3 computer architectures: x86_64, armhf, arm64. Most of us should be fine because our computer’s architecture should be x86_64. The previous ROS release is Kinetic Kame, which was released in May 2016.

One major change that Melodic brings is that C++ 14 is used over C++ 11, which means we can use all the goodness in C++ 14. For example, you can use auto as the function return type and the compiler will deduce the type for us.

Ubuntu 18.04, codenamed Bionic Beaver is an LTS version, as mentioned in the previous paragraph. It is released in April 2018 and is supported until May 2023 as well. The major change is that Gnome 3 is back, and Unity is gone. The use of Unity has been criticized to fragment the Linux community: the major player was Gnome.

Prerequisite

You should have already installed Ubuntu 18.04 before continuing.

Because we will install ROS Melodic system-wide in /opt/ros/, you should also have root access. It is rare and unsupported to install ROS on a user account.

This ROS version is released on May 23rd, 2018 and supported until May 2023, when the Ubuntu 18.04 will reach EOL (End of Life) as well. So, you should install ROS Noetic by then.

Step 1 — Install ROS Melodic repo

To install ROS Melodic on Ubuntu 18.04, we will need to configure the ROS repo, so the package installer knows where to find ROS packages. We will create a ros-melodic.list file and add the repo URL and OS meta info to that file.

The .list file will contain four pieces of information:

  • The first field deb means this is a Debian binary package repo (an alternative is deb-src, which means it is a Debian source package repo). The reason is because Ubuntu is based on Debian.
  • The second one is the URL of the ROS repo, which is the root of the Debian package.
  • The third one bionic is the distribution name, which in our case is the codename of Ubuntu 18.04. From this we can know the ROS packages for bionic are under http://packages.ros.org/ros/ubuntu/dists/bionic/.
  • The last component here is main, which is the section name.

To add the ROS Melodic repo, run the following command:

sudo sh -c 'echo "deb http://packages.ros.org/ros/ubuntu bionic main" > /etc/apt/sources.list.d/ros-melodic.list'
adding ros melodic repo on ubuntu 18.04

Note that this is different from the official installation instruction which recommends ros-latest.list. But the filename will not be true when the next ROS release is out.

Step 2 — Add official ROS Melodic repo keyring

Next, we will add the official ROS key to download authentic ROS Melodic packages to your Ubuntu 18.04 OS. Adding the key in important to avoid man-in-middle attack.

You can add the official ROS key in two methods and any of them will work. If you are not sure, follow the first method.

The first method uses apt-key, a dedicated command for APT key management. APT here means Advanced Package Tool, which is used for package management on Ubuntu and any other Debian based Linux distribution. If the following command does not work, which might be caused by network issue preventing you access keyserver.ubuntu.com, you can replace keyserver.ubuntu.com with the MIT equivalent pgp.mit.edu:

sudo apt-key adv --keyserver 'hkp://keyserver.ubuntu.com:80' --recv-key C1CF6E31E6BADE8868B172B4F42ED6FBAB17C654

The key is successfully added if you will see output like below, starting with Executing. From the output, we can see the ROS key is issued by Open Robotics who is the developer of ROS. You will also notice it automatically download the keyring file to the /tmp directory.

Executing: /tmp/apt-key-gpghome.MDeOTsvVrG/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
adding ros melodic keystring using apt-key

The second approach is to use curl to manually download the key and call apt-key to add it. If you don’t have it on your system, you can install it by sudo apt install curl). This is preferred if you are installing Melodic without an Internet connection or you won’t be able to access ubuntu.com if you are behind a security system.

curl -sSL 'http://keyserver.ubuntu.com/pks/lookup?op=get&search=0xC1CF6E31E6BADE8868B172B4F42ED6FBAB17C654' | sudo apt-key add -
adding ros melodic keystring using curl

Step 3 — Update ROS Melodic package index

Before we install Melodic meta packages, we will need to update local index to retrieve all the ROS packages locally. Here we will use the apt tool and pass the update parameter:

sudo apt update

You will see the following output with the ROS 18.04 repo url, which is highlighted in white.

Running sudo apt update for ros melodic installation

The following is the full output for your reference. You will see the line containing packages.ros.org/ros/ubuntu is highlighted.

vh@varhowto-com:~$ sudo apt update
[sudo] password for vh:
Hit:1 http://archive.ubuntu.com/ubuntu bionic InRelease
Get:2 http://security.ubuntu.com/ubuntu bionic-security InRelease [88.7 kB]
Hit:3 http://packages.ros.org/ros/ubuntu bionic InRelease
Get:4 http://archive.ubuntu.com/ubuntu bionic-updates InRelease [88.7 kB]
Get:5 http://security.ubuntu.com/ubuntu bionic-security/main amd64 Packages [746 kB]
Get:6 http://archive.ubuntu.com/ubuntu bionic-backports InRelease [74.6 kB]
Get:7 http://archive.ubuntu.com/ubuntu bionic-updates/main amd64 Packages [969 kB]
Get:8 http://security.ubuntu.com/ubuntu bionic-security/main i386 Packages [484 kB]
Get:9 http://security.ubuntu.com/ubuntu bionic-security/main amd64 DEP-11 Metadata [43.8 kB]
Get:10 http://security.ubuntu.com/ubuntu bionic-security/universe i386 Packages [624 kB]
Get:11 http://archive.ubuntu.com/ubuntu bionic-updates/main i386 Packages [694 kB]
Get:12 http://security.ubuntu.com/ubuntu bionic-security/universe amd64 Packages [673 kB]
Get:13 http://security.ubuntu.com/ubuntu bionic-security/universe amd64 DEP-11 Metadata [49.2 kB]
Get:14 http://archive.ubuntu.com/ubuntu bionic-updates/main Translation-en [329 kB]
Get:15 http://archive.ubuntu.com/ubuntu bionic-updates/main amd64 DEP-11 Metadata [306 kB]
Get:16 http://archive.ubuntu.com/ubuntu bionic-updates/universe i386 Packages [1,018 kB]
Get:17 http://security.ubuntu.com/ubuntu bionic-security/multiverse amd64 DEP-11 Metadata [2,464 B]
Get:18 http://archive.ubuntu.com/ubuntu bionic-updates/universe amd64 Packages [1,081 kB]
Get:19 http://archive.ubuntu.com/ubuntu bionic-updates/universe Translation-en [336 kB]
Get:20 http://archive.ubuntu.com/ubuntu bionic-updates/universe amd64 DEP-11 Metadata [279 kB]
Get:21 http://archive.ubuntu.com/ubuntu bionic-updates/multiverse amd64 DEP-11 Metadata [2,468 B]
Get:22 http://archive.ubuntu.com/ubuntu bionic-backports/universe amd64 DEP-11 Metadata [7,972 B]
Fetched 7,896 kB in 2s (3,795 kB/s)
Reading package lists… Done
Building dependency tree
Reading state information… Done
82 packages can be upgraded. Run 'apt list --upgradable' to see them.

Step 4 — Install ROS Melodic package on Ubuntu 18.04

Finally, we can install Melodic packages on your Ubuntu 18.04 OS. Like Ubuntu’s metapackages — ubuntu-dektop and ubuntu-desktop-mini, ROS also has its own metapackages. Those that are specific to Ubuntu 18.04 are:

  • ros-melodic-desktop-full
  • ros-melodic-desktop
  • ros-melodic-ros-base
  • ros-melodic-ros-core

By default, you can just install the desktop-full package, which is detailed in the following subsection. But the other 3 metapackages will also be explained for some edge cases, or deployment needs where you will not need any GUI or simulation packages. Installing the other 3 packages will most likely save the disk some space.

Install ros-melodic-desktop-full

If you are running a desktop environment in your Ubuntu, you will want to install ros-melodic-desktop-full, which will give you almost all the packages that you will ever needed, including all the basic ROS packages, perception packages (PCL and opencv), the GUI packages (rviz and rqt), visualization packages (rviz), simulation packages (Gazebo).

Specifically, the desktop-full package contains the following packages/metapackages:

  • desktop
  • perception
  • simulators
  • urdf_sim_tutorial

To install it, run

sudo apt install ros-melodic-desktop-full

You will see the following output. The whole installation will need 2.4 GB space for 1052 packages and download 533 MB data. Press Y or directly press enter to continue. As this is the biggest metapackage that depends on a lot of other packages, it will take quite some time, around 10 minutes to finish. It will take more time if you have a slower connection.

Running sudo apt install ros-melodic-desktop-full

Install ros-melodic-desktop

ros-melodic-desktop is a trimmed-down version of the desktop-full package, containing most official ROS tutorial packages but without perception (PCL, OpenCV, and image related packages) and simulators packages (gazebo, rqt, stage).

Specifically, the desktop package includes the following packages:

  • robot
  • viz
  • angles
  • common_tutorials
  • geometry_tutorials
  • joint_state_publisher_gui
  • ros_tutorials
  • roslint
  • urdf_tutorial
  • visualization_tutorials

To install it, run

sudo apt install ros-melodic-desktop

Install ros-melodic-base

ros-melodic-base is based on the core metapackage below and adds actionlib, bond_core, dynamic_reconfigure, and nodelet_core packages that are optional.

Specifically, this meta package contains the following packages:

  • ros_core
  • actionlib
  • bond_core
  • dynamic_reconfigure
  • nodelet_core

To install it, run

sudo apt install ros-melodic-base

Install ros-melodic-core

ros-melodic-core contains the bare minimum ROS packages, which are required for publishers, subscribers, services, launch files, and other core ROS concepts. Here is the full list of core packages:

  • catkin
  • class_loader
  • cmake_modules
  • common_msgs
  • gencpp
  • geneus
  • genlisp
  • genmsg
  • gennodejs
  • genpy
  • message_generation
  • message_runtime
  • pluginlib
  • ros
  • ros_comm
  • rosbag_migration_rule
  • rosconsole
  • rosconsole_bridge
  • roscpp_core
  • rosgraph_msgs
  • roslisp
  • rospack
  • std_msgs
  • std_srvs

To install it, run

sudo apt install ros-melodic-core

Set up ROS Melodic environment

After installing the Melodic desktop package, all the ROS commands are actually not in the PATH variable, which means you won’t be able to run any ROS commands or catkin won’t be able to find your ROS program files such as header files in your includes directory, then the compiling process will fail. Indeed, all the installation files are installed in /opt/ros/melodic/. We will need to manually set up the ROS environment by either running source /opt/ros/melodic/setup.bash or put this command in .bashrc file because we don’t want to run that setup.bash script every time we open a new terminal tab or window.

To add the setup.bash file to .bashrc, run

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

After this echo command, you can run tail ~/.bashrc to double check if it works. You will see the following output:

Adding ros melodic setup.bash to bashrc

Now you can open a new terminal tab (Ctrl-Shift-t) or new window (Ctrl-Shift-n) to make it take effect.

If you are using zsh instead of bash, you can run echo "source /opt/ros/noetic/setup.zsh" >> ~/.zshrc to put setup.zsh to your .zshrc file in your Linux home directory.

Verify Melodic installation

Woo-hoo! Now you know how to install ROS Melodic on Ubuntu 18.04. Before we stop for the day, let’s run some ROS commands to verify it’s installed.

We can just run roscd to go to the installation directory: /opt/ros/melodic. Note that, in the following screenshot, the terminal prompt has been changed to that directory.

roscd into opt ros melodic

Alternatively, you can run roscore to start a ROS master daemon. After you run it, you will see what appear in the following screenshot. The first line says it’s logging to a log file in the .ros directory in your home directory. In the summary section, you can see the ros distro currently running is melodic. Another valuable information here is the ROS_MASTER_URI line, which tells us that the master is running on the port 11311.

running roscore after installing ros melodic on ubuntu 18.04

Now the installation is complete. Enjoy yourself programming robots or learning ROS on your Ubuntu 18.04 machine!

4 steps to install ROS Melodic on Ubuntu 18.04

Time Needed : 15 minutes

  1. Set up ROS repo on Ubuntu 18.04

    Run this command to add the ROS package repo: sudo sh -c 'echo "deb http://packages.ros.org/ros/ubuntu bionic main" > /etc/apt/sources.list.d/ros-melodic.list'
    adding ros melodic repo on ubuntu 18.04

  2. Add Official ROS repo keyring

    To make sure we get authentic ROS Melodic package we will install, run sudo apt-key adv --keyserver 'hkp://keyserver.ubuntu.com:80' --recv-key C1CF6E31E6BADE8868B172B4F42ED6FBAB17C654.adding ros melodic keystring using apt key

  3. Update ROS package index

    Run sudo apt update to pull all the ROS Melodic packages in formation in Ubuntu 18.04.Running sudo apt update for ros melodic installation

  4. Install ROS Melodic desktop package on Ubuntu 18.04

    Here we will run sudo apt install ros-melodic-desktop-full to install all the ROS Melodic packages we will ever need.
    Running sudo apt install ros melodic desktop full

Tools
  • Terminal
  • curl
  • apt
Materials
  • Ubuntu 18.04

FAQ

  1. How to fix “Unable to locate package ros-melodic-desktop-full”?

    There are multiple reasons why you see Unable to locate package ros-melodic-desktop or ros-melodic-desktop .

    1. Make sure you followed the first 3 steps: add ROS Melodic repo, add ROS keyring, and run sudo apt update to have a local copy of the meta information of all Melodic packages.

    2. Make sure you have Ubuntu 18.04 or Debian 9 Stretch, not older Ubuntu version like 18.04 or Debian 8. Melodic only supports Ubuntu 18.04 and Debian 9, otherwise you will get this error message: “Unable to locate package ros-melodic-desktop-full”.

+11

By VarHowto Editor

Welcome to VarHowto!