Installing ROS on an Ubuntu 18.04

Installing ROS on an Ubuntu 18.04

May 25, 2021·Jingyao Zhang
Jingyao Zhang

image

0. Pre-installation Notes

The official ROS project releases multiple versions, which correspond to specific Ubuntu versions as shown below:

ROS VersionUbuntu Version
ROS Kinetic KameUbuntu 16.04
ROS Melodic MoreniaUbuntu 18.04
ROS Noetic NinjemysUbuntu 20.04

This guide introduces the installation method for ROS Melodic Morenia, which matches Ubuntu 18.04. The ROS official website provides precompiled software packages for Ubuntu and source code (not recommended). It is recommended to directly download the official precompiled packages.


1. Installation

1.1. Configure Ubuntu Repositories

Configure your Ubuntu repositories to allow “restricted”, “universe”, and “multiverse” components. Refer to the Ubuntu repository guide for assistance.

1.2. Set up sources.list

Set up your computer to install packages from packages.ros.org.

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

If the download is slow, you can switch to a nearby mirror. For example, for Tsinghua University:

sudo sh -c '. /etc/lsb-release && echo "deb http://mirrors.tuna.tsinghua.edu.cn/ros/ubuntu/ `lsb_release -cs` main" > /etc/apt/sources.list.d/ros-latest.list'

If connection issues persist, consider changing your Ubuntu apt sources (not related to the ROS website).

1.3. Set the Key

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

If the key server cannot be reached, try replacing hkp://keyserver.ubuntu.com:80 with hkp://pgp.mit.edu:80.

Alternatively, you can use curl if working behind a proxy:

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

1.4. Installation

Ensure your Debian package index is up-to-date:

sudo apt update

ROS contains many different libraries and tools. There are four default installation options, or you may install individual ROS packages.

If the steps below do not work, try using the alternative repository ros-shadow-fixed (English page).

Desktop-Full (recommended): Includes ROS, rqt, rviz, common libraries, 2D/3D simulators, navigation, and 2D/3D perception packages.

sudo apt install ros-melodic-desktop-full

Desktop: Includes ROS, rqt, rviz, and common libraries.

sudo apt install ros-melodic-desktop

ROS-Base: Includes core ROS packages, build, and communication libraries without GUI tools.

sudo apt install ros-melodic-ros-base

Individual Packages: Install a specific ROS package by replacing PACKAGE below with the name:

sudo apt install ros-melodic-PACKAGE

Example:

sudo apt install ros-melodic-slam-gmapping

To search available packages:

apt search ros-melodic

1.5. Initialize Rosdep

Before using ROS, you must initialize rosdep. It allows easy installation of system dependencies for source code or some core components of ROS:

sudo rosdep init
rosdep update

1.6. Set Environment

Automatically source the ROS environment in new zsh sessions:

echo "source /opt/ros/melodic/setup.zsh" >> ~/.zshrc
source ~/.zshrc

To set the environment only for the current zsh session:

source /opt/ros/melodic/setup.zsh

1.7. Install Build Tools

You have now installed the necessary packages to run core ROS. To create and manage your own ROS workspace, install tools like rosinstall:

sudo apt-get install python-rosinstall python-rosinstall-generator python-wstool build-essential

2. Test ROS

To verify ROS is installed correctly, enter:

roscore

If you see output like started core service [/rosout], the installation was successful.

Last updated on