ROS安装官方教程,以及如何解决安装过程中的报错
创始人
2025-06-01 20:56:20

本文参考ROS官方教程:http://wiki.ros.org/melodic/Installation/Ubuntu 安装 ros melodic,并解决了安装过程中出现的报错

我们正在为以下几个Ubuntu平台构建Debian软件包。这些软件包比基于源代码的构建更高效,也是我们推荐在Ubuntu上使用的安装方法。请注意,Ubuntu官方也提供了一些软件包。关于它们与我们提供的软件包的区别,请参阅UpstreamPackages以了解更多信息。

Distroamd64arm64armhf
ArtfulX
BionicXXX

1. 安装

1.1 配置

配置你的Ubuntu软件仓库(repositories),以允许使用“restricted”“universe”和“multiverse”存储库。你可以根据Ubuntu软件仓库指南来完成这项工作。

这一步通常是不需要的,如果执行了这一步可能会报错。

1.2 设置sources.list

设置sources.list,添加ROS官方软件源,使电脑可以安装来自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'
  • 尽量使用上面这个官方镜像源,如果速度太慢,可以从ROS镜像源挑选合适的软件源替换,比如清华(Tsinghua)或者中科大(USTC)的。

1.3 设置公钥 KEYS

在 Ubuntu 上安装 ROS 软件包时,需要添加 ROS 软件库的 GPG 公钥以进行软件包的验证和安全性检查

sudo apt install curl # if you haven't already installed curl
curl -s https://raw.githubusercontent.com/ros/rosdistro/master/ros.asc | sudo apt-key add -

解决报错:

  1. 执行上面第二条命令curl -s https://raw.githubusercontent.com/ros/rosdistro/master/ros.asc | sudo apt-key add -时,会报错:
xunyi@xavier:~$ curl -s https://raw.githubusercontent.com/ros/rosdistro/master/ros.asc | sudo apt-key add -
gpg: no valid OpenPGP data found.

可以把这条命令分开执行,分别执行以下两条命令:

curl -O https://raw.githubusercontent.com/ros/rosdistro/master/ros.asc
sudo apt-key add ros.asc
  1. 如果curl -O https://raw.githubusercontent.com/ros/rosdistro/master/ros.asc 报连接失败的错:
xunyi@xavier:~$ curl -O https://raw.githubusercontent.com/ros/rosdistro/master/ros.asc% Total    % Received % Xferd  Average Speed   Time    Time     Time  CurrentDload  Upload   Total   Spent    Left  Speed0     0    0     0    0     0      0      0 --:--:-- --:--:-- --:--:--     0curl: (7) Failed to connect to raw.githubusercontent.com port 443: Connection refused

解决方式:

sudo vim /etc/hosts# 加上一行
199.232.28.133 raw.githubusercontent.com

执行成功:

xunyi@xavier:~$ curl -O https://raw.githubusercontent.com/ros/rosdistro/master/ros.asc% Total    % Received % Xferd  Average Speed   Time    Time     Time  CurrentDload  Upload   Total   Spent    Left  Speed
100  1678  100  1678    0     0    860      0  0:00:01  0:00:01 --:--:--   859
xunyi@xavier:~$ ls
Desktop  Documents  Downloads  examples.desktop  Music  Pictures  Public  ros.asc  Templates  Videos
xunyi@xavier:~$ sudo apt-key add ros.asc
OK

1.4 安装

首先,更新软件包索引

sudo apt update

安装需要的ROS。这里提供了三个不同的 ROS 安装选项,分别是 Desktop-Full Install、Desktop Install 和 ROS-Base。

  • Desktop-Full Install 是一个完整版的 ROS 安装,包括 ROS、rqt、rviz、机器人通用库、2D/3D 模拟器和 2D/3D 感知等组件。这是一个推荐的安装选项。
sudo apt install ros-melodic-desktop-full
  • Desktop Install 包括 ROS、rqt、rviz 和机器人通用库,但不包括模拟器和感知组件。
sudo apt install ros-melodic-desktop
  • ROS-Base 则是一个轻量级的 ROS 安装,只包括 ROS 包、构建和通信库,不包含图形用户界面(GUI)工具。该选项适合需要更加自定义的用户或者资源有限的嵌入式系统。
sudo apt install ros-melodic-ros-base

我装的是ROS-Base,如果你不知道装哪个,就安装完整的ros-melodic-desktop-full。

我们可以通过以下命令查看ros-melodic有哪些可以用的软件包,它可以显示 Ubuntu 软件包管理器(apt)中所有与 ROS Melodic 相关的软件包列表。

apt search ros-melodic

1.5 设置环境

为方便后续开发,设置成每次打开一个新的终端时ROS环境变量都能够自动配置好(即添加到bash中)。

echo "source /opt/ros/melodic/setup.bash" >> ~/.bashrc
source ~/.bashrc

1.6 安装用于构建ROS包的依赖项和工具

sudo apt install python-rosdep python-rosinstall python-rosinstall-generator python-wstool build-essential
  • python-rosdep: 用于安装ROS依赖项的工具
  • python-rosinstall: 用于下载ROS软件包源代码的命令行工具
  • python-rosinstall-generator: 用于生成rosinstall文件的命令行工具
  • python-wstool: 用于管理多个源代码工作区的工具
  • build-essential: 包含C/C++编译器和其他必要的构建工具的软件包

1.6.1 初始化 rsdep

rosdep是一个用于安装ROS软件包所需系统依赖项的工具。在使用ROS时,如果要编译软件包,就需要使用rosdep来安装其所需的依赖项。

  • 安装ROS软件包
sudo apt install python-rosdep
  • 初始化,在计算机上创建一个默认的rosdep源列表
sudo rosdep init
  • 更新rosdep源列表,以确保其包含最新的软件包和依赖项信息。更新rosdep是一项重要任务,可以确保我们能够安装最新的系统依赖项,以编译和运行ROS软件包。
rosdep update

这条命令大概率或出错:

xunyi@xavier:~$ sudo rosdep init
Wrote /etc/ros/rosdep/sources.list.d/20-default.list
Recommended: please runrosdep updatexunyi@xavier:~$ rosdep update
reading in sources list data from /etc/ros/rosdep/sources.list.d
Hit https://raw.githubusercontent.com/ros/rosdistro/master/rosdep/osx-homebrew.yaml
Hit https://raw.githubusercontent.com/ros/rosdistro/master/rosdep/base.yaml
Hit https://raw.githubusercontent.com/ros/rosdistro/master/rosdep/python.yaml
Hit https://raw.githubusercontent.com/ros/rosdistro/master/rosdep/ruby.yaml
ERROR: unable to process source [https://raw.githubusercontent.com/ros/rosdistro/master/releases/fuerte.yaml]:Failed to download target platform data for gbpdistro:('The read operation timed out',)
Query rosdistro index https://raw.githubusercontent.com/ros/rosdistro/master/index-v4.yaml
ERROR: error loading sources list:('The read operation timed out',)

原因是近期国内Github Raw的可用IP越来越少。
可以通过修改rosdep源码中下载资源的函数来解决这一问题。https://ghproxy.com/网站 支持github的资源代理,非常好用,可以用此代理加速rosdep对Github Raw的访问,进而解决rosdep update超时问题。

  1. 打开包含资源下载函数的文件:
sudo vi /usr/lib/python2.7/dist-packages/rosdep2/sources_list.py
  1. download_rosdep_data函数中添加代理,加入这一行:
url="https://ghproxy.com/"+url

在这里插入图片描述

  1. 修改以下五个文件,全部添加代理,也就是找出所有的https://raw.githubusercontent.com,在前面加上'https://ghproxy.com/
一、/usr/lib/python2.7/dist-packages/rosdistro/__init__.pyDEFAULT_INDEX_URL = 'https://raw.githubusercontent.com/ros/rosdistro/master/index-v4.yaml'替换为:DEFAULT_INDEX_URL = 'https://ghproxy.com/https://raw.githubusercontent.com/ros/rosdistro/master/index-v4.yaml'
二、/usr/lib/python2.7/dist-packages/rosdep2/gbpdistro_support.pyFUERTE_GBPDISTRO_URL = 'https://raw.githubusercontent.com/ros/rosdistro/' \'master/releases/fuerte.yaml'替换为:FUERTE_GBPDISTRO_URL = 'https://ghproxy.com/https://raw.githubusercontent.com/ros/rosdistro/' \'master/releases/fuerte.yaml'
三、/usr/lib/python2.7/dist-packages/rosdep2/sources_list.pyDEFAULT_SOURCES_LIST_URL = 'https://raw.githubusercontent.com/ros/rosdistro/master/rosdep/sources.list.d/20-	        default.list'替换为:DEFAULT_SOURCES_LIST_URL = 'https://ghproxy.com/https://raw.githubusercontent.com/ros/rosdistro/master/rosdep/sources.list.d/20-default.list'
四、/usr/lib/python2.7/dist-packages/rosdep2/rep3.pyREP3_TARGETS_URL = 'https://raw.githubusercontent.com/ros/rosdistro/master/releases/targets.yaml'替换为:REP3_TARGETS_URL = 'https://ghproxy.com/https://raw.githubusercontent.com/ros/rosdistro/master/releases/targets.yaml'
五、/usr/lib/python2.7/dist-packages/rosdistro/manifest_provider/github.py这个文件有两处需要修改的

再次执行rosdep update,成功:

xunyi@xavier:~$ rosdep update
reading in sources list data from /etc/ros/rosdep/sources.list.d
Hit https://raw.githubusercontent.com/ros/rosdistro/master/rosdep/osx-homebrew.yaml
Hit https://raw.githubusercontent.com/ros/rosdistro/master/rosdep/base.yaml
Hit https://raw.githubusercontent.com/ros/rosdistro/master/rosdep/python.yaml
Hit 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://ghproxy.com/https://raw.githubusercontent.com/ros/rosdistro/master/index-v4.yaml
Skip end-of-life distro "ardent"
Skip end-of-life distro "bouncy"
Skip end-of-life distro "crystal"
Skip end-of-life distro "dashing"
Skip end-of-life distro "eloquent"
Add distro "foxy"
Skip end-of-life distro "galactic"
Skip end-of-life distro "groovy"
Add distro "humble"
Skip end-of-life distro "hydro"
Skip end-of-life distro "indigo"
Skip end-of-life distro "jade"
Skip end-of-life distro "kinetic"
Skip end-of-life distro "lunar"
Add distro "melodic"
Add distro "noetic"
Add distro "rolling"
updated cache in /home/xunyi/.ros/rosdep/sources.cache


至此,ROS就已经安装成功,可以通过roscore命令查看:

xunyi@xavier:~$ roscore
... logging to /home/xunyi/.ros/log/4c9a576e-c927-11ed-bdec-ec2e98ca659d/roslaunch-xavier-16851.log
Checking log directory for disk usage. This may take a while.
Press Ctrl-C to interrupt
Done checking log file disk usage. Usage is <1GB.started roslaunch server http://xavier:36291/
ros_comm version 1.14.13SUMMARY
========PARAMETERS* /rosdistro: melodic* /rosversion: 1.14.13NODESauto-starting new master
process[master]: started with pid [16865]
ROS_MASTER_URI=http://xavier:11311/setting /run_id to 4c9a576e-c927-11ed-bdec-ec2e98ca659d
process[rosout-1]: started with pid [16878]
started core service [/rosout]

相关内容

热门资讯

「科技推荐」沧海麻将.能不能开... 「科技推荐」沧海麻将.能不能开挂[太坑了原来有挂]您好:沧海麻将这款游戏可以开挂,确实是有挂的,需要...
独家讲解.微乐家乡大贰.可以开... 亲.微乐家乡大贰这款游戏是可以开挂的,确实是有挂的,通过添加客服【9183893】很多玩家在这款游戏...
今日重大通报“欢乐联盟是不是有... 您好:欢乐联盟这款游戏可以开挂,确实是有挂的,需要了解加客服微信【3636476】很多玩家在这款游戏...
独家发现.边锋老友棋牌.怎么开... 独家发现.边锋老友棋牌.怎么开挂.[详细开挂教程]亲,边锋老友棋牌这个游戏其实有挂的,确实是有挂的,...
玩家必看“功夫四川麻将可以开挂... 您好:功夫四川麻将这款游戏可以开挂,确实是有挂的,需要软件加微信【69174242】,很多玩家在功夫...