First, check whether the locale supports UTF-8 encoding. You can run the following command to check and set the UTF-8 encoding.
xxxxxxxxxxlocale # Check for UTF-8 supportsudo apt update && sudo apt install localessudo locale-gen en_US en_US.UTF-8sudo update-locale LC_ALL=en_US.UTF-8 LANG=en_US.UTF-8export LANG=en_US.UTF-8locale # Verify the configuration is successfulNote: The locale can be different, but must support UTF-8 encoding.
Start the Ubuntu universe repository
xxxxxxxxxxsudo apt install software-properties-commonsudo add-apt-repository universeAdd the ROS 2 apt repository to the system and authorize our GPG key with apt.
xxxxxxxxxxsudo apt update && sudo apt install curl gnupg lsb-release -ysudo curl -sSL https://raw.githubusercontent.com/ros/rosdistro/master/ros.key -o /usr/share/keyrings/ros-archive-keyring.gpgAdd the repository to the source list
xxxxxxxxxxecho "deb [arch=$(dpkg --print-architecture) signed-by=/usr/share/keyrings/ros-archive-keyring.gpg] http://packages.ros.org/ros2/ubuntu $(source /etc/os-release && echo $UBUNTU_CODENAME) main" | sudo tee /etc/apt/sources.list.d/ros2.list > /dev/nullFirst, update the apt repository cache:
xxxxxxxxxxsudo apt UpdateThen upgrade the installed software (ROS2 packages are built on the frequently updated Ubuntu system. Please ensure your system is up to date before installing new packages):
xxxxxxxxxxsudo apt upgradeInstall the desktop version of ROS2 (recommended), which includes ROS, RViz, examples, and tutorials. The installation command is as follows. If you need to install a different version, replace "humble" in the command with the corresponding version number:
xxxxxxxxxxsudo apt install ros-humble-desktop python3-argcompleteInstall the colcon build tool
xxxxxxxxxxsudo apt install python3-colcon-common-extensionsWhen executing ROS2 programs in a terminal, you need to run the following command to configure the environment:
xxxxxxxxxxsource /opt/ros/humble/setup.bashYou must execute the above command each time you open a new terminal. Alternatively, you can run the following command to add the environment configuration instructions to the "~/.bashrc" file, eliminating the need to manually configure the environment each time you start a new terminal.
xxxxxxxxxxecho "source /opt/ros/humble/setup.bash" >> ~/.bashrcAt this point, ROS2 has been installed and configured.
The ROS2 desktop version has integrated some example nodes. You can test whether ROS2 is successfully installed by running these example nodes.
xxxxxxxxxxros2 run demo_nodes_cpp talkerxxxxxxxxxxros2 run demo_nodes_cpp listenerThe turtle simulator, TurtleSim, is a classic teaching tool in ROS. It helps you quickly understand core ROS concepts.
xxxxxxxxxxros2 run turtlesim turtlesim_nodexxxxxxxxxxros2 run turtlesim turtle_teleop_keyxxxxxxxxxxros2 topic echo /turtle1/cmd_velAfter installing ROS2, if you want to uninstall it, you can execute the following command:
xxxxxxxxxxsudo apt remove ~nros-humble-* && sudo apt autoremoveYou can also delete the ROS2 repository:
xxxxxxxxxxsudo rm /etc/apt/sources.list.d/ros2.listsudo apt updatesudo apt autoremove