1.配置 Ubuntu 存储库
将 Ubuntu 存储库配置为允许"restricted"、"universe"和"multiverse"
2.设置源列表
将计算机设置为接受packages.ros.org的软件。
sudo sh -c 'echo "deb http://packages.ros.org/ros/ubuntu $(lsb_release -sc) main" > /etc/apt/sources.list.d/ros-latest.list'
3.设置密钥
注意,密钥需要按照时间、版本相关查找,本文用这个密钥目前是可用的。
sudo apt-key adv --keyserver 'hkp://keyserver.ubuntu.com:80' --recv-key C1CF6E31E6BADE8868B172B4F42ED6FBAB17C654
4.更新软件源
sudo apt update
5.安装
桌面全安装:(推荐): ROS, rqt, rviz,机器人通用库, 2D/3D 模拟器和 2D/3D 感知
sudo apt install ros-melodic-desktop-full
桌面安装:ROS、rqt、rviz和机器人通用库
sudo apt install ros-melodic-desktop
ROS-Base: (裸骨)ROS 包、生成和通信库。无 GUI 工具
sudo apt install ros-melodic-ros-base
单个包:您还可以安装特定的 ROS 包(用包名称的破折号替换下划线)
sudo apt install ros-melodic-PACKAGE
例如:
sudo apt install ros-melodic-slam-gmapping
要查找可用包,请使用:
apt search ros-melodic
6.【可选】添加环境变量
echo "source /opt/ros/melodic/setup.bash" >> ~/.bashrc
source ~/.bashrc
如果安装了多个 ROS 分发,则*/.bashrc必须只为当前使用的版本提供setup.bash。
如果只想更改当前 shell 的环境,可以键入:
source /opt/ros/melodic/setup.bash
7.【可选】生成包的依赖项
到目前为止,您已经安装了运行核心 ROS 包所需的内容。要创建和管理自己的 ROS 工作区,可以单独分发各种工具和要求。例如,rosinstall是一个常用的命令行工具,使您能够使用一个命令轻松下载许多 ROS 包的源树。
要安装此工具和其他用于构建 ROS 包的依赖项,请运行:
sudo apt install python-rosdep python-rosinstall python-rosinstall-generator python-wstool build-essential
8.初始化rosdep
在可以使用许多 ROS 工具之前,您需要初始化rosdep。rosdep 使您能够轻松为要编译的源安装系统依赖项,并且需要在 ROS 中运行某些核心组件。
如果您尚未安装 rosdep,请按照以下方式操作。
sudo apt install python-rosdep
初始化 rosdep
sudo rosdep init
rosdep update
9. Q&A
(1)错误描述:
ming@ming:~$ rosdep update
reading in sources list data from /etc/ros/rosdep/sources.list.d
ERROR: unable to process source [https://raw.githubusercontent.com/ros/rosdistro/master/rosdep/osx-homebrew.yaml]:
<urlopen error [Errno 111] Connection refused> (https://raw.githubusercontent.com/ros/rosdistro/master/rosdep/osx-homebrew.yaml)
ERROR: unable to process source [https://raw.githubusercontent.com/ros/rosdistro/master/rosdep/base.yaml]:
<urlopen error [Errno 111] Connection refused> (https://raw.githubusercontent.com/ros/rosdistro/master/rosdep/base.yaml)
ERROR: unable to process source [https://raw.githubusercontent.com/ros/rosdistro/master/rosdep/python.yaml]:
<urlopen error [Errno 111] Connection refused> (https://raw.githubusercontent.com/ros/rosdistro/master/rosdep/python.yaml)
ERROR: unable to process source [https://raw.githubusercontent.com/ros/rosdistro/master/rosdep/ruby.yaml]:
<urlopen error [Errno 111] Connection refused> (https://raw.githubusercontent.com/ros/rosdistro/master/rosdep/ruby.yaml)
Hit https://raw.githubusercontent.com/ros/rosdistro/master/releases/fuerte.yaml
Query rosdistro index https://raw.githubusercontent.com/ros/rosdistro/master/index-v4.yaml
Add distro "ardent"
ERROR: error loading sources list:
<urlopen error <urlopen error [Errno 111] Connection refused> (https://raw.githubusercontent.com/ros/rosdistro/master/ardent/distribution.yaml)>
解决方法:添加nameserver
sudo gedit /etc/resolv.conf
nameserver 8.8.8.8
nameserver 8.8.4.4
保存并退出,执行下列语句使其生效
sudo apt-get update
rosdep update