网上教程非常多,但对于ubuntu22.04 不是很适用,软件源不能使用。采用网上教程更换软件源都会报错,只有添加ROS2 apt仓库后才不报错,报错信息如下:
ros处理好后安装相应的软件还是安装不了,会报如下错:
解决办法使用aptitude :sudo aptitude install ros-humble-desktop
ubuntu22.04 安装ros步骤如下:
1. 配置好ros软件安装源
a 添加证书
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
这一步如果遇到Failed to connect to raw.githubusercontent.com
,请访问 https://www.ipaddress.com 网站,在查询框中输入:raw.githubusercontent.com
并回车,在里面找到相应的的ipv4地址:
这四个IP地址随便选一个,使用sudo vi /etc/hosts
将IP和域名添加到/etc/hosts
文件中,如下图:
b 添加ros仓库
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
添加源:
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
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
2. 安装ros:
首先需要更新apt(以前是 apt-get,官方建议使用apt而非apt-get),apt是用于从互联网仓库搜索,安装,升级,卸载软件或操作系统的工具
sudo apt update
sudo aptitude install ros-humble-desktop
3. 设置环境变量:
source /opt/ros/humble/setup.bash
echo "source /opt/ros/humble/setup.bash" >>~/.bashrc
4. 校验是否安装成功:
ros2 run turtlesim turtlesim_node
ros2 run turtlesim turtle_teleop_key