【随记】在WSL2下安装ROS

安装WSL

首先安装WSL2,具体可以查看官方文档
这里简述一下过程:
1.用管理员运行power shell
2.启用相关选项

dism.exe /online /enable-feature /featurename:Microsoft-Windows-Subsystem-Linux /all /norestart

3.设置默认WSL版本

wsl --set-default-version 2

4.在微软商店安装一个linux版本,注意安装ROS需要是ubuntu。实验室老师要求是18.04,因此个人安装的是ubuntu18.04

5.重启windows

修改软件源

不同系统版本请自行按照清华源官方文档进行修改

#备份源文件
sudo cp /etc/apt/sources.list /etc/apt/sources_origin.list
sudo vim /etc/apt/sources.list

将文件内容全部删除,替换为以下内容

# 默认注释了源码镜像以提高 apt update 速度,如有需要可自行取消注释
deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ bionic main restricted universe multiverse
# deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ bionic main restricted universe multiverse
deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ bionic-updates main restricted universe multiverse
# deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ bionic-updates main restricted universe multiverse
deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ bionic-backports main restricted universe multiverse
# deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ bionic-backports main restricted universe multiverse
deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ bionic-security main restricted universe multiverse
# deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ bionic-security main restricted universe multiverse

# 预发布软件源,不建议启用
# deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ bionic-proposed main restricted universe multiverse
# deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ bionic-proposed main restricted universe multiverse

安装ROS

根据官方文档进行安装
先更新下环境

sudo apt update
sudo apt upgrade

添加ROS包的清华镜像源

sudo sh -c '. /etc/lsb-release && echo "deb http://mirrors.tuna.tsinghua.edu.cn/ros/ubuntu/ `lsb_release -cs` main" > /etc/apt/sources.list.d/ros-latest.list'

设置密钥

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 -

若报错 gpg: no valid OpenPGP data found.
可能为DNS污染导致,解决方法为:
通过网站查询得到raw.githubusercontent.com的真实IP地址
打开Host文件:sudo vim /etc/hosts
在最后一行添加:185.199.108.133 raw.githubusercontent.com,若你查到的IP地址不为185.199.108.133则另作修改即可。


若卡在了这一步,请自行科学上网解决,或者自行寻找可靠的镜像站


再更新一下

sudo apt update

安装ROS
注意版本对应,14.04对应indigo,16.04对应kinetic,18.04对应melodic.20.04对应noetic,我是18.04因此这里是ros-melodic版本

sudo apt install ros-melodic-desktop-full

配置环境

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

安装一些开发包

sudo apt install python-rosdep python-rosinstall python-rosinstall-generator python-wstool build-essential

初始化依赖管理器(这一步也有timeout错误,请自行科学上网)

sudo apt install python-rosdep
sudo rosdep init
rosdep update

最后在命令行键入 roscore 即可启用ROS核心服务
再新建一个终端,输入rosrun turtlesim turtlesim_node 运行样例程序,若成功弹出乌龟窗口,即安装成功啦

你可能感兴趣的:(研究生时期笔记,ubuntu,linux,运维)