How to install ROS2 on Ubuntu - Step by step guide[Humble, Iron, or other]

Install ROS2 on Ubuntu

Install ROS2 on Ubuntu

Follow these commands one by one to install ROS2 on Ubuntu PC.

1. Check Locale

$ locale
locale output

Make sure you have a locale which supports UTF-8. If you're in a minimal environment (like a Docker container), the locale may be something like POSIX.

If locale is not installed or you're getting a different output, install it using:

$ sudo apt update && sudo apt install locales
$ sudo locale-gen en_US en_US.UTF-8
$ sudo update-locale LC_ALL=en_US.UTF-8 LANG=en_US.UTF-8
$ export LANG=en_US.UTF-8
$ locale

Note: If you're in India, your output might be LANG=en_IN.UTF-8

2. Setup Sources

$ apt-cache policy | grep universe
universe output

If you are getting different output, enable universe with:

$ sudo apt install software-properties-common
$ sudo add-apt-repository universe

3. Add the ROS 2 apt repositories to your system

$ sudo apt update && sudo apt install curl gnupg lsb-release
$ sudo curl -sSL https://raw.githubusercontent.com/ros/rosdistro/master/ros.key | sudo tee /usr/share/keyrings/ros-archive-keyring.gpg > /dev/null
$ echo "deb [arch=$(dpkg --print-architecture) signed-by=/usr/share/keyrings/ros-archive-keyring.gpg] http://packages.ros.org/ros2/ubuntu $(lsb_release -cs) main" | sudo tee /etc/apt/sources.list.d/ros2.list > /dev/null
$ sudo apt update

4. Install ROS 2 (Humble, Iron, or other)

To install ROS 2 Humble Desktop (example):

$ sudo apt install ros-humble-desktop

5. Source ROS 2 setup files

Add this line to your ~/.bashrc to source automatically:

source /opt/ros/humble/setup.bash

Then run:

$ source ~/.bashrc

6. Install dependencies for building ROS packages

$ sudo apt install -y python3-colcon-common-extensions python3-rosdep python3-argcomplete

7. Initialize rosdep

$ sudo rosdep init
$ rosdep update

You're now ready to use ROS 2 on Ubuntu. 🚀