1.设置编码
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
2.使能代码库
sudo apt install software-properties-common
sudo add-apt-repository universe
3.现在用apt添加带ROS 2 GPG关键字
sudo apt update && sudo apt install curl gnupg lsb-release
sudo curl -sSL https://raw.githubusercontent.com/ros/rosdistro/master/ros.key -o /usr/share/keyrings/ros-archive-keyring.gpg
4.将存储库添加到源列表中
echo "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/null
5.安装ROS2 Iron
sudo apt update
sudo apt upgrade
sudo apt install ros-iron-desktop ros-iron-ros-base ros-dev-tools
6.ROS2测试
在terminal 1 运行下面的指令:
source /opt/ros/iron/setup.bash
ros2 run demo_nodes_cpp talker
在terminal 2 运行下面的指令:
source /opt/ros/iron/setup.bash
ros2 run demo_nodes_py listener
7.卸载
sudo apt remove ~nros-iron-* && sudo apt autoremove
删除存储库
sudo rm /etc/apt/sources.list.d/ros2.list
sudo apt updatesudo apt autoremovesudo apt upgrade
8.使用
您需要在打开的每个新 shell 上运行此命令才能访问 ROS 2 命令
source /opt/ros/iron/setup.bash
如果您不希望每次打开新 shell 时都必须获取安装文件,则可以将命令添加到 shell 启动脚本中:
echo "source /opt/ros/iron/setup.bash" >> ~/.bashrc
检查环境变量
printenv | grep -i ROS
ROS_VERSION=2
ROS_PYTHON_VERSION=3
ROS_DISTRO=iron