目录
一、准备工作
控制面板——程序——程序和功能——启动或关闭Windows功能
开启如图所示三项,重启电脑
二、安装Ubuntu 22.04.1 LTS
1. 下载Ubuntu 22.04.1 LTS
打开Microsoft Store,搜索并下载Ubuntu 22.04.1 LTS
(安装Windows Subsystem for Linux前一定要先安装Ubuntu,否则移动Ubuntu位置会报错)
2. 移动到非系统盘
ps:默认安装在C盘,可以移动安装位置,建议移动到其它盘
三、启动Ubuntu遇到的报错及解决方案
报错:
WslRegisterDistribution failed with error: 0x800701bc
解决方案:
下载安装适用于 x64 计算机的最新 WSL2 Linux 内核更新包
下载链接
https://wslstorestorage.blob.core.windows.net/wslblob/wsl_update_x64.msi
安装后
报错:
adduser: Please enter a username matching the regular expression configured
via the NAME_REGEX[_SYSTEM] configuration variable. Use the `--force-badname'
option to relax this check or reconfigure NAME_REGEX.
解决方案:
把大写的首字母,改成小写即可
ps:输入的密码不显示
四、换源
Ubuntu默认的软件源在国外,可能会造成下载软件卡顿,因此需要换源,这里我选择更换为阿里源。
1.双击Ubuntu22.04 LTS图标,在命令行中输入
# 备份原来的软件源 sudo cp /etc/apt/sources.list /etc/apt/sources.list.bak # 编辑软件源 sudo nano /etc/apt/sources.list
2.将原来的内容替换为阿里源
deb http://mirrors.aliyun.com/ubuntu/ jammy main restricted universe multiverse deb-src http://mirrors.aliyun.com/ubuntu/ jammy main restricted universe multiverse deb http://mirrors.aliyun.com/ubuntu/ jammy-security main restricted universe multiverse deb-src http://mirrors.aliyun.com/ubuntu/ jammy-security main restricted universe multiverse deb http://mirrors.aliyun.com/ubuntu/ jammy-updates main restricted universe multiverse deb-src http://mirrors.aliyun.com/ubuntu/ jammy-updates main restricted universe multiverse deb http://mirrors.aliyun.com/ubuntu/ jammy-proposed main restricted universe multiverse deb-src http://mirrors.aliyun.com/ubuntu/ jammy-proposed main restricted universe multiverse deb http://mirrors.aliyun.com/ubuntu/ jammy-backports main restricted universe multiverse deb-src http://mirrors.aliyun.com/ubuntu/ jammy-backports main restricted universe multiverse
Ctrl + O保存, enter, Ctrl + X退出
3.更改后
4. 更新升级软件
在Ubuntu命令行中依次执行如下命令:
# 更新软件源 sudo apt-get update -y # 升级所有软件 sudo apt-get upgrade -y
五、安装ROS
1. 设置编码
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
2. 添加源
1.通过检查此命令的输出,确保已启用Ubuntu Universe存储库。
apt-cache policy | grep universe
①正常情况
②若没有看到像上面这样的输出行,依次执行如下命令:
sudo apt install software-properties-common sudo add-apt-repository universe
2.继续执行如下命令:
sudo apt update && sudo apt install curl gnupg 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) signed-by=/usr/share/keyrings/ros-archive-keyring.gpg] http://packages.ros.org/ros2/ubuntu $(source /etc/os-release && echo $UBUNTU_CODENAME) main" | sudo tee /etc/apt/sources.list.d/ros2.list > /dev/null
①正常情况
②报错:curl: (7) Failed to connect to raw.githubusercontent.com port 443 after 0 ms: Connection refused
解决
sudo nano /etc/hosts
加上一行
199.232.28.133 raw.githubusercontent.com
Ctrl + O保存, enter, Ctrl + X退出
3. 安装ROS
sudo apt update sudo apt upgrade
安装桌面版
sudo apt install ros-humble-desktop
安装时间较长,慢慢等待
4. 设置环境变量
source /opt/ros/humble/setup.bash echo " source /opt/ros/humble/setup.bash" >> ~/.bashrc
5. 测试
①通过以下命令启动一个数据的发布者节点:
ros2 run demo_nodes_cpp talker
②启动另一个终端,通过以下命令启动一个数据的订阅者节点
ros2 run demo_nodes_py listener