[ROS] 在 Ubuntu 16.04 系统上安装 ROS Kinetic
ROS 的发行版很多,之前的文章中我们介绍过在 Ubuntu 14.04 上安装 indigo。
时光荏苒,Ubuntu 和 ROS 的长期支持版本都已经更新了,对于最新的 Ubuntu 16.04 通常情况下我们更多地使用其稳定版本 Kinetic。这篇文章就讲下 Kinetic 版本在 Ubuntu 下的安装。
0、安装环境
Ubuntu 16.04 LTS
1、配置源
使用 ROS 官方源:
1 | sudo sh -c 'echo "deb http://packages.ros.org/ros/ubuntu $(lsb_release -sc) main" > /etc/apt/sources.list.d/ros-latest.list' |
使用国内镜像源:
1 | sudo sh -c '. /etc/lsb-release && echo "deb http://mirrors.ustc.edu.cn/ros/ubuntu/ $DISTRIB_CODENAME main" > /etc/apt/sources.list.d/ros-latest.list' |
设置Key:
1 | sudo apt-key adv --keyserver hkp://ha.pool.sks-keyservers.net:80 --recv-key 421C365BD9FF1F717815A3895523BAEEB01FA116 |
PS:如果上述地址有问题,可以换成 hkp://pgp.mit.edu:80 或者 hkp://keyserver.ubuntu.com:80 重试。
更新安装包:
1 | sudo apt-get update |
升级安装包(通常情况下不需要这一步):
1 | sudo apt-get upgrade |
2、安装 ROS:
推荐新手安装 Desktop-Full 版本,其他版本都有一些东西不全。安装命令如下:
1 | sudo apt-get install ros-kinetic-desktop-full |
或者直接点击:
点击这里
其他版本安装方式参见 [1]:
3、初始化 rosdep:
使用以下命令初始化 rosdep:
1 2 | sudo rosdep init rosdep update |
4、环境配置:
为了方便每次系统重启时可以自动配置好 ros 相关环境,进行以下操作(根据你是 bash 还是 zsh 命令行环境采用分别的操作):
如果你是 bash 环境:
在 ~/.bashrc 文件末尾增加如下代码:
1 | source /opt/ros/kinetic/setup.bash |
或者直接运行以下命令:
1 | echo "source /opt/ros/kinetic/setup.bash" >> ~/.bashrc |
运行如下命令使配置生效:
1 | source ~/.bashrc |
如果你是 zsh 环境:
在 ~/.zshrc 文件末尾增加如下代码:
1 | source /opt/ros/kinetic/setup.zsh |
或者直接运行以下命令:
1 | echo "source /opt/ros/kinetic/setup.zsh" >> ~/.zshrc |
运行如下命令使配置生效:
1 | source ~/.zshrc |
这样以后每次重启都可以自动配置好环境了。
5、安装开发工具:
很多常见包都使用 rosinstall 等工具,使用如下命令安装:
1 | sudo apt-get install python-rosinstall python-rosinstall-generator python-wstool build-essential |
到此安装结束,开始你的 ROS 之旅吧!
常见问题:
1、64位系统下:Some packages could not be installed. 错误
在很多64位机器上如果安装 ros-kinetic-desktop-full 会出现如下错误:
Reading package lists... Done
Building dependency tree
Reading state information... Done
Some packages could not be installed. This may mean that you have
requested an impossible situation or if you are using the unstable
distribution that some required packages have not yet been created
or been moved out of Incoming.
The following information may help to resolve the situation:
The following packages have unmet dependencies:
ros-kinetic-desktop-full : Depends: ros-kinetic-desktop but it is not going to be installed
Depends: ros-kinetic-simulators but it is not going to be installed
E: Unable to correct problems, you have held broken packages.
解决这一问题的方法一个是只安装核心库 ros-kinetic-desktop 或者可以尝试先卸载下面的组件:
1 | sudo apt-get remove gazebo-* sdformat-* |
2、错误:default sources list file already exists
在运行 sudo rosdep init 时可能出现如下错误:
ERROR: default sources list file already exists:
/etc/ros/rosdep/sources.list.d/20-default.list
Please delete if you wish to re-initialize
通常这是因为你之前曾经安装过 ROS 系统的某个版本,只需按照提示删除已经存在的初始化文件即可:
1 | sudo rm /etc/ros/rosdep/sources.list.d/20-default.list |
然后再重新运行 sudo rosdep init 就没有问题了。
3、错误:cannot download default sources list
在运行 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.
有可能是没有安装证书库所致,可以尝试如下命令:
1 | sudo apt-get install ca-certificates |
其实这个文件也比较简单,这一行所做的命令只是下载这个文件放到 /etc/ros/rosdep/sources.list.d/20-default.list 下面,因此你也可以自行保存下面的内容:
1 2 3 4 5 6 7 8 9 10 | # 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 |
然后你可以运行:
1 | rosdep update |
参考文献:
[1] http://wiki.ros.org/kinetic/Installation/Ubuntu
4、错误:/opt/ros/kinetic/etc/catkin/profile.d/20.transform.bash:42: command not found: complete
如果你在运行 source 时出现如下错误:
/opt/ros/kinetic/etc/catkin/profile.d/05.catkin_make.bash:67: command not found: complete
/opt/ros/kinetic/etc/catkin/profile.d/05.catkin_make_isolated.bash:65: command not found: complete
/opt/ros/kinetic/share/rosbash/rosbash:982: command not found: complete
/opt/ros/kinetic/share/rosbash/rosbash:983: command not found: complete
/opt/ros/kinetic/share/rosbash/rosbash:984: command not found: complete
/opt/ros/kinetic/share/rosbash/rosbash:985: command not found: complete
/opt/ros/kinetic/share/rosbash/rosbash:986: command not found: complete
/opt/ros/kinetic/share/rosbash/rosbash:987: command not found: complete
/opt/ros/kinetic/share/rosbash/rosbash:988: command not found: complete
/opt/ros/kinetic/share/rosbash/rosbash:989: command not found: complete
/opt/ros/kinetic/share/rosbash/rosbash:990: command not found: complete
/opt/ros/kinetic/share/rosbash/rosbash:991: command not found: complete
/opt/ros/kinetic/share/rosbash/rosbash:992: command not found: complete
/opt/ros/kinetic/share/rosbash/rosbash:993: command not found: complete
/opt/ros/kinetic/share/rosbash/rosbash:994: command not found: complete
/opt/ros/kinetic/share/rosbash/rosbash:995: command not found: complete
/opt/ros/kinetic/share/rosbash/rosbash:996: command not found: complete
/opt/ros/kinetic/share/rosbash/rosbash:997: command not found: complete
/opt/ros/kinetic/share/rosbash/rosbash:998: command not found: complete
/opt/ros/kinetic/share/rosbash/rosbash:999: command not found: complete
/opt/ros/kinetic/share/rosbash/rosbash:1000: command not found: complete
/opt/ros/kinetic/share/rosbash/rosbash:1001: command not found: complete
/opt/ros/kinetic/share/rosbash/rosbash:1002: command not found: complete
/opt/ros/kinetic/share/rosbash/rosbash:1003: command not found: complete
/opt/ros/kinetic/etc/catkin/profile.d/20.transform.bash:23: command not found: complete
/opt/ros/kinetic/etc/catkin/profile.d/20.transform.bash:42: command not found: complete
有很大可能是你把命令行环境配置搞反了,请注意在 bash 和 zsh 中分别使用 setup.bash 和 setup.zsh 两个不同的文件。请参照 4、环境配置 进行修改。