Ubuntu18.04 安装ROS melodic
1.添加ROS软件源
sudo sh -c 'echo "deb http://packages.ros.org/ros/ubuntu $(lsb_release -sc) main" > /etc/apt/sources.list.d/ros-latest.list'
2.添加公钥
sudo apt-key adv --keyserver 'hkp://keyserver.ubuntu.com:80' --recv-key C1CF6E31E6BADE8868B172B4F42ED6FBAB17C654
3.更新系统
sudo apt update
4.安装
这里安装的是桌面完整版(推荐): 包含 ROS、rqt、rviz、机器人通用库、2D/3D 模拟器、导航以及 2D/3D 感知包
sudo apt install ros-melodic-desktop-full
如果这步提示安装失败的话,出现如下的错误的话
E: Failed to fetch http://us.archive.ubuntu.com/ubuntu/pool/universe/v/vtk6/libvtk6.3_6.3.0+dfsg1-11build1_amd64.deb Connection failed [IP: 91.189.91.26 80]
E: Unable to fetch some archives, maybe run apt-get update or try with --fix-missing?
按提示内容进行系统更新,然后在执行安装命令。
5.初始化rosdep(这步是最让人头疼的)
在上述第4步安装完成后执行以下命令:
sudo rosdep init
rosdep update
5.1如果执行sudo rosdep init
出现错误
ERROR:cannot download default sources list from:
https://raw.githubusercontent.com/ros/rosdistro/master/rosdep/sources.list.d/20-default.list
Website may be down
但使用浏览器可以打开上述的网址
解决方法:
打开hosts文件
sudo gedit /etc/hosts
在文件末尾添加
151.101.84.133 raw.githubusercontent.com
保存后退出再尝试
5.2如果执行sudo rosdep init
出现上述的错误,但是使用浏览器打不开上述的网址
解决办法:手动创建20-default.list文件,然后把别人的内容复制进去
首先建立一个文件夹
sudo /etc/ros/rosdep/sources.list.d
然后使用
sudo gedit 20-default.list
打开文件,将以下的内容复制进去
# os-specific listings first
yaml https://raw.githubusercontent.com/ros/rosdistro/master/rosdep/osx-homebrew.yaml osx
# generic
yaml https://raw.githubusercontent.com/ros/rosdistro/master/rosdep/base.yaml
yaml https://raw.githubusercontent.com/ros/rosdistro/master/rosdep/python.yaml
yaml https://raw.githubusercontent.com/ros/rosdistro/master/rosdep/ruby.yaml
gbpdistro https://raw.githubusercontent.com/ros/rosdistro/master/releases/fuerte.yaml fuerte
# newer distributions (Groovy, Hydro, ...) must not be listed anymore, they are being fetched from the rosdistro index.yaml instead
保存后退出,然后在执行
sudo rosdep init
5.3如果执行rosdep update
一直出现如下图的错误
这是网络问题,因为这一步需要去github上面加载一些东西,要访问外网,可以的话搞个VPN翻个墙就好了。如果翻不了墙的话可以试一下以下的方法:
新开一个终端:
sudo pip install rosdepc
如果显示没有pip的可以试一下pip3:
sudo pip3 install rosdepc
如果pip3还没有的话执行下面的命令:
sudo apt-get install python3-pip
sudo pip install rosdepc
然后使用以下的命令代替sudo rosdep init 和rosdep update两条命令:
sudo rosdepc init
rosdepc update
6.设置环境
echo "source /opt/ros/melodic/setup.bash" >> ~/.bashrc
source ~/.bashrc
7.安装rosinstall,便利的工具(非必须)
sudo apt-get install python-rosinstall python-rosinstall-generator python-wstool build-essential
8.检查ROS是否安装成功
1.查看在计算机的opt目录下是否有ros目录,目录下是否有对应的melodic(ros版本号命名的文件)
2.打开终端,输入roscore命令,然后运行小乌龟命令可以看到ROS已经成功在ubuntu上运行起来。
roscore
再开一个终端
rosrun turtlesim turtlesim_node
开第三个终端
rosrun turtlesim turtle_teleop_key
然后你就可以尝试用键盘控制小乌龟了,也就说明ros安装成功了。