Noetic

  1. 配置Ubuntu软件仓库

  2. 设置sources.list

    sudo sh -c '. /etc/lsb-release && echo "deb http://mirrors.tuna.tsinghua.edu.cn/ros/ubuntu/ focal 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
    sudo apt install ros-noetic-desktop-full
    
  5. 设置环境变量

    echo "source /opt/ros/noetic/setup.bash" >> ~/.bashrc
    source ~/.bashrc
    
  6. 安装依赖

    sudo apt install python3-rosdep python3-rosinstall python3-rosinstall-generator python3-wstool build-essential
    
  7. 初始化 rosdep

    sudo rosdep init
    rosdep update
    

PS:在http://wiki.ros.org/cn/noetic/Installation/Ubuntu中,是没有最后两项的,但是在http://wiki.ros.org/noetic/Installation/Ubuntu中是有的,建议加上这两步。

Foxy

  1. 设置语言环境

    locale  # check for UTF-8
    
    sudo apt update && sudo apt install locales
    sudo locale-gen en_US en_US.UTF-8
    sudo update-locale LC_ALL=en_US.UTF-8 LANG=en_US.UTF-8
    export LANG=en_US.UTF-8
    
    locale  # verify settings
    
  2. 设置源

    新建 /etc/apt/sources.list.d/ros2-latest.list,内容为:

    deb http://mirrors.tuna.tsinghua.edu.cn/ros2/ubuntu/ focal main
    

    然后再输入如下命令,信任 ROS 的 GPG Key,并更新索引:

    sudo apt install curl gnupg2
    curl -s https://raw.githubusercontent.com/ros/rosdistro/master/ros.asc | sudo apt-key add -
    sudo apt update
    

    这里我会有报错,好像是清华源的问题,直接把源换成官方源就好:shell deb http://packages.ros.org/ros2/ubuntu/ focal main

  3. 安装ROS2包

    sudo apt update
    sudo apt install ros-foxy-desktop
    
  4. 设置环境变量

    echo "source /opt/ros/foxy/setup.bash" >> ~/.bashrc
    source ~/.bashrc
    
  5. 安装依赖包

    sudo apt install python3-argcomplete ros-foxy-rmw* ros-foxy-ros1-bridge python3-colcon-common-extensions
    

环境变量

使用张瑞雷老师的bash脚本,开启bash时手动选择ROS版本 修改~/.bashrc如下

# ROS 1.0 Noetic or ROS 2.0 Foxy
echo ROS 1.0 or ROS 2.0? 1=Noetic 2=Foxy 
read ROS
if (($ROS==1));then
source /opt/ros/noetic/setup.bash
echo "Noetic"
elif (($ROS==2));then
source /opt/ros/foxy/setup.bash
echo "Foxy"
else
echo "Non-ROS"
fi