问题
sudo apt install ros-humble-gazebo-*显示网络不可达,这是因为sources.list中的镜像源有问题,换成清华源可以解决问题
解决
1 设置Ubuntu镜像源为清华镜像源
1.1 备份source.list文件
sudo cp /etc/apt/sources.list /etc/apt/sources.list.bak
1.2 更改文件权限
sudo chmod 777 /etc/apt/sources.list
1.3 使用nano编辑器打开并删除原内容
sudo nano /etc/apt/sources.list
手动将报错的源都删掉
1.4 访问清华镜像源并按照页面提示拷贝源代码至source.list
2 设置ros2获取链接
2.1 添加ros2的资源库密钥
sudo apt install curl gnupg2
sudo curl -sSL https://raw.githubusercontent.com/ros/rosdistro/master/ros.key -o /usr/share/keyrings/ros-archive-keyring.gpg
如果报错:curl: (56) OpenSSL SSL_read: 连接被对方重置, errno 104
将curl的命令更换为
sudo wget -O /usr/share/keyrings/ros-archive-keyring.gpg https://raw.githubusercontent.com/ros/rosdistro/master/ros.key
2.2 将镜像链接加载进本地source.list目录
echo "deb [arch=$(dpkg --print-architecture) signed-by=/usr/share/keyrings/ros-archive-keyring.gpg] https://mirrors.tuna.tsinghua.edu.cn/ros2/ubuntu jammy main" | sudo tee /etc/apt/sources.list.d/ros2.list > /dev/null
sudo apt update
sudo apt upgrade
2.3 执行安装/更新
#安装gazebo
sudo apt install ros-humble-gazebo-*
#安装ros2
sudo apt install ros-humble-desktop
将source /opt/ros/humble/setup.bash添加到.bashrc中
到此问题解决。