安装ROS2到Ubuntu 20.04

提前准备:

1,查看系统版本号

$ lsb_release -a

No LSB modules are available.

Distributor ID: Ubuntu

Description: Ubuntu 20.04.2 LTS

Release: 20.04

Codename: focal

2, 更换清华镜像源

Ubuntu 的软件源配置文件是 /etc/apt/sources.list。将系统自带的该文件做个备份,将该文件替换为下面内容,即可使用 TUNA 的软件源镜像。

如果你连接不上这个网址(https://mirrors.tuna.tsinghua.edu.cn/ros2/ubuntu/pool/main/r/ros-foxy-desktop/),请尝试使用你的手机移动热点连接。

选择你的ubuntu版本: https://mirror.tuna.tsinghua.edu.cn/help/ubuntu/

# 默认注释了源码镜像以提高 apt update 速度,如有需要可自行取消注释

deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ focal main restricted universe multiverse

# deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ focal main restricted universe multiverse

deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ focal-updates main restricted universe multiverse

# deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ focal-updates main restricted universe multiverse

deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ focal-backports main restricted universe multiverse

# deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ focal-backports main restricted universe multiverse

deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ focal-security main restricted universe multiverse

# deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ focal-security main restricted universe multiverse

# 预发布软件源,不建议启用

# deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ focal-proposed main restricted universe multiverse

# deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ focal-proposed main restricted universe multiverse

或者使用命令替换, 执行如下命令自动替换

sudo sed -i "s@http://.*archive.ubuntu.com@https://mirrors.tuna.tsinghua.edu.cn@g" /etc/apt/sources.list

sudo sed -i "s@http://.*security.ubuntu.com@https://mirrors.tuna.tsinghua.edu.cn@g" /etc/apt/sources.list

3,安装获取清华源的CA证书

cd /tmp

wget http://archive.ubuntu.com/ubuntu/pool/main/c/ca-certificates/ca-certificates_20211016~20.04.1_all.deb

sudo dpkg -i ./ca-certificates_20211016~20.04.1_all.deb

sudo apt update

sudo apt upgrade

开始安装:

1,设置语言环境(Set locale

确保你的语言环境能支持UTF-8。如果你使用的是minimal environment,比如docker的容器,那语言环境可能是类似POSIX之类的。我们需要进行下面的测试。但是,如果你正在使另外一种支持UTF-8的语言,应该也是可以的。

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,设置源 (Setup Sources

首先,将ROS2 apt仓库添加到你的系统,具体做法为:

sudo apt update && sudo apt install curl gnupg2 lsb-release

sudo curl -sSL https://raw.githubusercontent.com/ros/rosdistro/master/ros.key -o /usr/share/keyrings/ros-archive-keyring.gpg

echo "deb [arch=$(dpkg --print-architecture)] http://mirror.tuna.tsinghua.edu.cn/ros2/ubuntu $(lsb_release -cs) main" | sudo tee /etc/apt/sources.list.d/ros2.list > /dev/null

或者

sudo apt update && sudo apt install curl gnupg2 lsb-release

curl http://repo.ros2.org/repos.key | sudo apt-key add -

sudo sh -c 'echo "deb [arch=$(dpkg --print-architecture)] http://mirror.tuna.tsinghua.edu.cn/ros2/ubuntu $(lsb_release -cs) main" > /etc/apt/sources.list.d/ros2-latest.list'

3,安装ROS2的包(Install ROS 2 packages

首先,更新apt repository。

sudo apt update

推荐安装桌面版本: ROS, RViz, demos, tutorials.

sudo apt install ros-foxy-desktop

4,环境设置(Environment setup

Sourcing设置脚本

通过sourcing下面的文件设置环境:

source /opt/ros/foxy/setup.bash

5,安装参数补全 (optional)

ROS2 命令行工具使用argcomplete进行自动补全。所以,如果你想进行自动补全,需要安装argcomplete。

sudo apt install -y python3-argcomplete

6,测试几个例子(Try some examples

在一个终端中,source了设置文件之后,运行一个c++的发布消息的应用。

source /opt/ros/foxy/setup.bash

ros2 run demo_nodes_cpp talker

在另外一个终端中,source了设置文件之后,运行一Python的接收消息的应用。

source /opt/ros/foxy/setup.bash

ros2 run demo_nodes_py listener

ros2 node list

ros2 topic list

7, Uninstall卸载ROS2

If you need to uninstall ROS 2 or switch to a source-based install once you have already installed from binaries, run the following command:

sudo apt remove ~nros-foxy-* && sudo apt autoremove

You may also want to remove the repostiory:

sudo rm /etc/apt/sources.list.d/ros2-latest.list

sudo rm /etc/apt/sources.list.d/ros2.list

sudo apt update

sudo apt autoremove

# Consider upgrading for packages previously shadowed.

sudo apt upgrade

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值