ROS2 Install
Main introduction to setting up the ROS2 Humble version environment.
- It is recommended to perform the following operations based on VNC / NoMachine remote desktop or by connecting a display.
- The ROS2 environment is built in a Docker container. It is recommended to install and learn how to use Docker first.
- Ubuntu is the officially preferred and primarily supported distribution for ROS2. We will build the ROS2 environment based on Docker's Ubuntu image.
Pull Docker Image
Use the docker pull command to pull the Ubuntu 22.04 Docker image.
docker pull ubuntu:22.04
Write Docker Script
Use a script to start the Ubuntu 22.04 Docker container.
You need to write a startup script ros_humble.sh:
vi ros_humble.sh
Add the following content to the script:
#!/bin/bash
xhost +
docker run -it \
--net=host \
--env="DISPLAY" \
--env="QT_X11_NO_MITSHM=1" \
-v /tmp/.X11-unix:/tmp/.X11-unix \
--name ros2 \
ubuntu:22.04 /bin/bash
Parameter description:
xhost +: Allow Docker container to access X11 server-it: Run container in interactive mode--net=host: Use host's network stack--env="DISPLAY": Set environment variable for displaying X11 graphical interface--env="QT_X11_NO_MITSHM=1": Set environment variable for Qt application display-v /tmp/.X11-unix:/tmp/.X11-unix: Mount X11 Unix domain socket for displaying X11 graphical interface--name ros2: Specify name for the containerubuntu:22.04: Use Ubuntu 22.04 image/bin/bash: Start Bash shell inside the container
Start Docker Container
Use the bash command to start the script.
bash ros_humble.sh
Install Humble
Check Encoding Environment
Ensure that the environment for installing Humble supports UTF-8 encoding.
locale
If the system encoding format is UTF-8, you can see similar information output in the terminal:
LANG=en_US.UTF-8
LANGUAGE=
LC_CTYPE="en_US.UTF-8"
LC_NUMERIC="en_US.UTF-8"
LC_TIME="en_US.UTF-8"
LC_COLLATE="en_US.UTF-8"
LC_MONETARY="en_US.UTF-8"
LC_MESSAGES="en_US.UTF-8"
LC_PAPER="en_US.UTF-8"
LC_NAME="en_US.UTF-8"
LC_ADDRESS="en_US.UTF-8"
LC_TELEPHONE="en_US.UTF-8"
LC_MEASUREMENT="en_US.UTF-8"
LC_IDENTIFICATION="en_US.UTF-8"
LC_ALL=
If the terminal output information is not UTF-8 encoded, you can enter the following commands in the terminal to install and modify the encoding environment:
apt update && apt install locales
locale-gen en_US en_US.UTF-8
echo "export LANG=en_US.UTF-8" >> ~/.bashrc
source ~/.bashrc
Set Software Sources and Keys
Ensure the system is in the latest environment, then enable the Ubuntu Universe repository and add ROS2 keys.
apt-cache policy | grep universe
apt install software-properties-common curl -y
add-apt-repository universe
curl -sSL https://raw.githubusercontent.com/ros/rosdistro/master/ros.key -o /usr/share/keyrings/ros-archive-keyring.gpg
If you encounter the error: curl: (7) Failed to connect to raw.githubusercontent.com port 443 after 43 ms: Connection refused
Solution: Visit https://www.ipaddress.com/ to search for the raw.githubusercontent.com domain, and add the resulting IP address to the /etc/hosts file.
vi /etc/hosts
Add the following content:
185.199.110.133 raw.githubusercontent.com
Then re-run the command to add ROS2 keys.
curl -sSL https://raw.githubusercontent.com/ros/rosdistro/master/ros.key -o /usr/share/keyrings/ros-archive-keyring.gpg
Add the repository to the sources list:
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" | tee /etc/apt/sources.list.d/ros2.list > /dev/null
Install Humble
Use the following command to install Humble full desktop version.
apt update && apt upgrade
apt install ros-humble-desktop-full -y
Install ROS2 Development Tools
Use the following command to install ROS2 development tools.
apt install ros-dev-tools -y
Set Environment Variables
Use the following command to set environment variables:
echo "source /opt/ros/humble/setup.bash" >> ~/.bashrc
source ~/.bashrc
Save Docker Image
Currently, all our modifications are based on the Ubuntu 22.04 Docker container. We need to save this modified container as an image for direct use next time.
Note: If not saved as an image, you will need to reinstall the ROS2 environment when starting the container next time.
docker commit ros2 ros_humble:1.0
Parameter description:
ros2: The previously specified container nameros_humble:1.0: The name of the saved image
Wait for the commit to complete. After completion, you will see similar information output:
sha256:32288d439ffab73505d0754d4c43d8aad83210441b41553118e81ff6ab2887af
Modify Startup Script
Modify the startup image in the startup script ros_humble.sh to the image name just saved:
#!/bin/bash
xhost +
docker run -it \
--net=host \
--env="DISPLAY" \
--env="QT_X11_NO_MITSHM=1" \
-v /tmp/.X11-unix:/tmp/.X11-unix \
ros_humble:1.0 /bin/bash