Win10-WSL-Ubuntu18.04-ROS-melodic 安装与配置

一、WSL 安装 Ubuntu18.04

  1. Win10 启用 WSL

管理员身份运行:

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

重启电脑。

  1. 打开 Microsoft Store,安装 Ubuntu18.04

  2. 启动 Ubuntu18.04,创建账号、密码

  3. 安装 Windows Terminal(可选)

用 scoop 安装。

1
scoop install windows-terminal

windows-terminal 简单设置:字体、启动目录。

1
2
3
4
5
6
7
8
9
10
{
"guid": "{c6eaf9f4-32a7-5fdc-b5cf-066e8a4b1e40}",
"hidden": false,
"fontFace": "Jetbrains Mono",
"fontSize": 11,
"name": "Ubuntu-18.04",
"source": "Windows.Terminal.Wsl",
"startingDirectory": "//wsl$/Ubuntu-18.04//home/bo",

}
  1. 设置源,更新(可选)

打开配置文件: sudo nano /etc/apt/sources.list, 替换成以下内容:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
# 默认注释了源码镜像以提高 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

ref: https://mirrors.tuna.tsinghua.edu.cn/help/ubuntu/

更新:sudo apt update

升级:sudo apt upgrade

  1. 安装 ZSH、oh-my-zsh(可选)

参考 zsh & oh-my-zsh 安装配置

二、安装 ROS-melodic

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

  1. 设置源,URL: http://mirrors.tuna.tsinghua.edu.cn/ros/
1
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'
  1. 设置 keys
1
sudo apt-key adv --keyserver 'hkp://keyserver.ubuntu.com:80' --recv-key C1CF6E31E6BADE8868B172B4F42ED6FBAB17C654
  1. 安装
1
2
3
4
5
6
7
sudo apt update

# 建议完全安装 (Recommended)
# 含:ROS, rqt, rviz, robot-generic libraries,
# 2D/3D simulators and 2D/3D perception

sudo apt install ros-melodic-desktop-full
  1. 设置环境变量
1
2
3
# zsh
echo "source /opt/ros/melodic/setup.zsh" >> ~/.zshrc
source ~/.zshrc
  1. 安装必要的依赖
1
2
3
sudo apt install python-rosdep
sudo rosdep init
rosdep update

sudo rosdep init 需要从 raw.githubusercontent.com 下载文件。

如果报错,可以试下修改 hosts:

1
2
3
4
# 打开hosts文件
sudo nano /etc/hosts
# 在文件末尾添加
151.101.84.133 raw.githubusercontent.com
  1. 测试一下
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
roscore

# 会出现几行 log:
# started roslaunch server http://DESKTOP-FL776UK:56357/
# ros_comm version 1.14.10
#
#
# SUMMARY
# ========
#
# PARAMETERS
# * /rosdistro: melodic
# * /rosversion: 1.14.10
# ...
# started core service [/rosout]
#
  1. 测试一下小乌龟
  • 先在 win10 下安装 X Server:scoop install vcxsrv.

  • 然后依次在 Ubuntu18.04下打开三个 terminal:

1
2
3
4
5
6
7
8
# terminal - 1
roscore

# terminal - 2
rosrun turtlesim turtlesim_node

# terminal - 3
rosrun turtlesim turtle_teleop_key

windows terminal 分屏快捷键:

快捷键 功能
ctrl + shift + w closePane
alt + shift + - splitPane: horizontal
alt + shift + + splitPane: vertical