How To Install ROS2 Humble On PC (Running Ubuntu 22.04 LTS)

INSTALLING ROS HUMBLE DESKTOP

Follow the instructions (step by step) to install ros-humble-desktop on your dev PC. here’s a link to the documentation.

The basic steps (following the documentation link) to install ros-humble-desktop on your dev PC are:

  • Set locale
locale  # check for UTF-8

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  # verify settings
  • Setup Sources
sudo apt install software-properties-common

sudo add-apt-repository universe


sudo apt update && sudo apt install curl -y

sudo curl -sSL https://raw.githubusercontent.com/ros/rosdistro/master/ros.key -o /usr/share/keyrings/ros-archive-keyring.gpg


echo "deb [arch=$(dpkg --print-architecture) signed-by=/usr/share/keyrings/ros-archive-keyring.gpg] http://packages.ros.org/ros2/ubuntu $(. /etc/os-release && echo $UBUNTU_CODENAME) main" | sudo tee /etc/apt/sources.list.d/ros2.list > /dev/null
  • Install ros2 package (ros-humble-desktop)
sudo apt update

sudo apt upgrade

sudo apt install ros-humble-desktop
  • Next, add the following command to the .bashrc file to enable automatic sourcing of the ros humble environment and installed packages whenever you open a new terminal.
echo "source /opt/ros/humble/setup.bash" >> ~/.bashrc

After these, you can go to the next step below.

INSTALLING AND SETTING UP COLCON FOR BUILDING ROS2 PACKAGES

Colcon is required to build ros2 packages created in your ros workspace. 

  • Install colcon
sudo apt install python3-colcon-common-extensions
  • Setup colcon_cd
echo "source /usr/share/colcon_cd/function/colcon_cd.sh" >> ~/.bashrc

echo "export _colcon_cd_root=/opt/ros/humble/" >> ~/.bashrc
  • Setup colcon tab completion
echo "source /usr/share/colcon_argcomplete/hook/colcon-argcomplete.bash" >> ~/.bashrc

With all the above added to the .bashrc file, the colcon environment and functions will be automatically activated whenever you open a new terminal as well as automatic sourcing of the ros2 humble environment.

To learn more about colcon, checkout the documentation.

You can check if ros2 humble and colcon source command have been successfully added to the .bashrc file by running the following in the terminal:

sudo nano ~/.bashrc

you should see the following highlighted texts (in the image below) at the bottom of your .bashrc file:

INSTALLING ROSDEP

Rosdep is a dependency management utility that can work with packages and external libraries. It is a command-line utility for identifying and installing dependencies to build or install a package.

It is most often invoked before building a workspace, where it is used to install the dependencies of the packages within that workspace.

[Ref: Documentation link]

Follow the instructions below to install rosdep:

sudo apt-get update

sudo apt install python3-rosdep2

sudo rosdep init #NOTE:this might give an error, do not worry, just continue

rosdep update

INSTALL SETUPTOOLS FOR BUILDING ROS2 PYTHON PACKAGES

sudo apt install python3-pip

pip3 install setuptools==58.2.0

CREATING A ROS2 WORKSPACE

  • In the root folder of your Dev PC (i.e the home directory)
  • Create a ros workspace folder. I would be using the name in the picture above – ros-dev-ws
mkdir -p ~/ros-dev-ws/src
  • change the directory into the root ros workspace folder
cd ~/ros-dev-ws/src
  • Build the workspace initially with colcon (while still in the root workspace folder)
colcon build

You should now see three other folders – build, install, and log – apart from the src folder already created earlier.

  • Let’s set up automatic sourcing for the created ros workspace (ros-dev-ws) in the .bashrc file so that it is automatically sourced whenever you open a new terminal. Run in terminal:
echo "source ~/ros-dev-ws/install/setup.bash" >> ~/.bashrc

TEST WITH HELLOWORLD PACKAGE

  • Open a new terminal and go to your ros workspace folder:
cd ~/ros-dev-ws
  • Change the directory into the src folder:
cd /src
  • Clone my HelloWorld ROS2 cpp and py packages:
git clone https://github.com/samuko-things/helloworld_ros2.git
  • Change the directory to the root workspace folder:
cd ../
  • Optionally, run rosdep to install any necessary dependencies (specified in their package.xml file):
rosdep install -i --from-path src --rosdistro humble -y
  • Build the packages with colcon:
colcon build --packages-select helloworld_cpp

colcon build --packages-select helloworld_py --symlink-install
  • Open two separate terminals. In one of the terminals, run:
ros2 run helloworld_cpp talker
  • In the other run:
ros2 run helloworld_py listener