ROS的安装与卸载

本文最后更新于 2024年3月7日 晚上

本文主要分享了在Linux下ROS的安装与版本管理。

安装

不同的ubuntu版本对应不同版本的ros,具体可查询ros官网

http://wiki.ros.org/ROS/Installation

ubuntu16.04以及更老的版本对应ROS Kinetic Kame

ubuntu18.04对应ROS Melodic Morenia

ubuntu20.04对应ROS Noetic Ninjemys

下面开始安装ROS Melodic,详细安装教程可以参考下面的官网连接:

http://wiki.ros.org/melodic/Installation/Ubuntu

1. 安装

1
2
3
4
sudo sh -c 'echo "deb http://packages.ros.org/ros/ubuntu $(lsb_release -sc) main" > /etc/apt/sources.list.d/ros-latest.list' 
sudo apt-key adv --keyserver 'hkp://keyserver.ubuntu.com:80' --recv-key C1CF6E31E6BADE8868B172B4F42ED6FBAB17C654
sudo apt update
sudo apt install ros-melodic-desktop-full

2. 环境设置

1
2
3
4
5
6
7
echo "source /opt/ros/melodic/setup.bash" >> ~/.bashrc
echo "export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/opt/ros/melodic/lib" >> ~/.bashrc
source ~/.bashrc
# 如果你使用 zsh,替换其中的 bash, 你可以用以下命令来设置你的shell
echo "source /opt/ros/melodic/setup.zsh" >> ~/.zshrc
echo "export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/opt/ros/melodic/lib" >> ~/.zshrc
source ~/.zshrc

3. 安装依赖项

1
2
3
4
sudo apt install python-rosdep python-rosinstall python-rosinstall-generator python-wstool build-essential
sudo apt install python-rosdep
sudo rosdep init
rosdep update

rosdep update报错:The read operation timed out'

原因:网站被墙

解决方法:

https://blog.csdn.net/weixin_44028876/article/details/120201324

  1. 打开终端执行:

    1
    sudo gedit /etc/ros/rosdep/sources.list.d/20-default.list
  2. 替换20-default.list文件内容如下:

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    # os-specific listings first
    yaml https://mirror.ghproxy.com/https://raw.githubusercontent.com/ros/rosdistro/master/rosdep/osx-homebrew.yaml osx

    # generic
    yaml https://mirror.ghproxy.com/https://raw.githubusercontent.com/ros/rosdistro/master/rosdep/base.yaml
    yaml https://mirror.ghproxy.com/https://raw.githubusercontent.com/ros/rosdistro/master/rosdep/python.yaml
    yaml https://mirror.ghproxy.com/https://raw.githubusercontent.com/ros/rosdistro/master/rosdep/ruby.yaml
    gbpdistro https://mirror.ghproxy.com/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
  3. 终端重新执行:

    1
    rosdep update
  4. 成功运行的输出结果为:

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    reading in sources list data from /etc/ros/rosdep/sources.list.d
    Hit https://mirror.ghproxy.com/https://raw.githubusercontent.com/ros/rosdistro/master/rosdep/osx-homebrew.yaml
    Hit https://mirror.ghproxy.com/https://raw.githubusercontent.com/ros/rosdistro/master/rosdep/base.yaml
    Hit https://mirror.ghproxy.com/https://raw.githubusercontent.com/ros/rosdistro/master/rosdep/python.yaml
    Hit https://mirror.ghproxy.com/https://raw.githubusercontent.com/ros/rosdistro/master/rosdep/ruby.yaml
    Hit https://mirror.ghproxy.com/https://raw.githubusercontent.com/ros/rosdistro/master/releases/fuerte.yaml
    Query rosdistro index 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"
    Skip end-of-life 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"
    Add distro "iron"
    Skip end-of-life distro "jade"
    Skip end-of-life distro "kinetic"
    Skip end-of-life distro "lunar"
    Skip end-of-life distro "melodic"
    Add distro "noetic"
    Add distro "rolling"
    updated cache in /home/lll25655/.ros/rosdep/sources.cache

4. 安装ros与opencv的桥接工具包

1
sudo apt-get install ros-melodic-cv-bridge ros-melodic-tf ros-melodic-message-filters ros-melodic-image-transport

5. 其他

1
2
sudo apt install --reinstall ros-melodic-roslaunch
sudo apt-get install python-catkin-tools

6. 验证ros是否安装成功

1
2
3
4
roscore  # 第一个终端
rosrun turtlesim turtlesim_node # 第二个终端
rosrun turtlesim turtle_teleop_key # 第三个终端
# 鼠标聚焦于第三个终端,使用键盘方向键移动小乌龟,按键盘Q键退出。

使用

ROS知识积累

卸载

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
# 卸载 ROS
sudo apt-get remove ros-*
sudo apt-get purge ros-*

# 删除与 ROS 相关的依赖项
sudo apt-get remove ros-melodic-ros*
sudo apt-get remove ros-melodic-rviz
sudo apt-get remove ros-melodic-robot*

# 删除ROS源列表
sudo rm /etc/apt/sources.list.d/ros-latest.list
sudo rm /etc/ros/rosdep/sources.list.d/20-default.list

# 删除 ROS 安装目录
sudo rm -r /opt/ros/melodic

# 删除ROS安装生成的任何残留文件
sudo rm -rf ~/.ros

# 注释掉~/.bashrc和~/.zshrc里的
source /opt/ros/melodic/setup.zsh
export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/opt/ros/melodic/lib

# 关机重启

提示

如果你的主要工作是在ROS上进行的,那么ROS有自带的库就使用ROS自带的库,尽量减少自己另外装库,增加兼容性,减少报错。

比如,自己源码安装的PCL最好不要安装到系统根目录下,也就是默认的/usr/local/下。因为如果安装到了/usr/local/下,最后链接PCL的库的时候会默认链接到这个路径下的库。但是绝大部分搭建在ROS平台的工程都是使用ROS自带的pcl-1.8的,这个时候虽然编译可以通过,但是运行的时候会出错。血泪教训。

参考链接

Ubuntu18.04运行Vins-Fusion

Ubuntu18安装新版本PCL-1.13,并和ROS自带PCL-1.8共存


ROS的安装与卸载
http://zeyulong.com/posts/84f91530/
作者
龙泽雨
发布于
2024年1月10日
许可协议