sudo cp /etc/apt/sources.list /etc/apt/sources.list.bak
该命令打开源文件可能会比较慢
sudo gedit /etc/apt/sources.list
将文件里的替换为
deb https://mirrors.ustc.edu.cn/ubuntu/ focal main restricted universe multiverse
deb https://mirrors.ustc.edu.cn/ubuntu/ focal-updates main restricted universe multiverse
deb https://mirrors.ustc.edu.cn/ubuntu/ focal-backports main restricted universe multiverse
deb https://mirrors.ustc.edu.cn/ubuntu/ focal-security main restricted universe multiverse
# deb-src https://mirrors.ustc.edu.cn/ubuntu/ focal main restricted universe multiverse
# deb-src https://mirrors.ustc.edu.cn/ubuntu/ focal-updates main restricted universe multiverse
# deb-src https://mirrors.ustc.edu.cn/ubuntu/ focal-backports main restricted universe multiverse
# deb-src https://mirrors.ustc.edu.cn/ubuntu/ focal-security main restricted universe multiverse
## Pre-released source, not recommended.
# deb https://mirrors.ustc.edu.cn/ubuntu/ focal-proposed main restricted universe multiverse
# deb-src https://mirrors.ustc.edu.cn/ubuntu/ focal-proposed main restricted universe multiverse
然后执行
sudo apt-get update
再执行
sudo apt-get upgrade
sudo sh -c '. /etc/lsb-release && echo "deb http://mirrors.ustc.edu.cn/ros/ubuntu/ $DISTRIB_CODENAME main" > /etc/apt/sources.list.d/ros-latest.list'
sudo apt-key adv --keyserver 'hkp://keyserver.ubuntu.com:80' --recv-key C1CF6E31E6BADE8868B172B4F42ED6FBAB17C654
sudo apt-get update
sudo apt-get install ros-noetic-desktop-full
sudo apt-get install ros-noetic-rqt*
sudo mkdir -p /home/one/git/
cd /home/one/git/
sudo git clone https://gitee.com/one_DS/rosdistro.git
若找不到命令,安装git即可
sudo apt-get install git
sudo cp /usr/lib/python3/dist-packages/rosdep2/main.py /usr/lib/python3/dist-packages/rosdep2/main.py.bak
sudo cp /usr/lib/python3/dist-packages/rosdep2/rep3.py /usr/lib/python3/dist-packages/rosdep2/rep3.py.bak
sudo cp /usr/lib/python3/dist-packages/rosdistro/__init__.py /usr/lib/python3/dist-packages/rosdistro/__init__.py.bak
sudo cp /usr/lib/python3/dist-packages/rosdep2/sources_list.py /usr/lib/python3/dist-packages/rosdep2/sources_list.py.bak
sudo apt install python3-rosdep2
sudo gedit /usr/lib/python3/dist-packages/rosdep2/main.py
sudo gedit /usr/lib/python3/dist-packages/rosdep2/rep3.py
sudo gedit /usr/lib/python3/dist-packages/rosdistro/__init__.py
sudo gedit /usr/lib/python3/dist-packages/rosdep2/sources_list.py
sudo rosdep init
(1)错误1
ERROR: cannot download default sources list from:
https : //raw.githubusercontent.com/ros/rosdistro/master/rosdep/sources.list.d/20-default.list
Website may be down.
这一步按正常来说应该是成功的,出现这个错误说明没替换成功!!!重新返回 5、替换原文件网址到本地下载 重新替换,要记得保存!!
(2)错误2
在运行sudo rosdep init后出现下所示错误:
ERROR: default sources list file already exists:
/etc/ros/rosdep/sources.list.d/20-default.list
Please delete if you wish to re-initialize
执行
sudo rm /etc/ros/rosdep/sources.list.d/20-default.list
再执行
sudo rosdep init
sudo cp /etc/ros/rosdep/sources.list.d/20-default.list /etc/ros/rosdep/sources.list.d/20-default.list.bak
sudo gedit /etc/ros/rosdep/sources.list.d/20-default.list
rosdep update
这样就是成功了!!
echo "source /opt/ros/noetic/setup.bash" >> ~/.bashrc
source ~/.bashrc
sudo apt install python3-rosinstall python3-rosinstall-generator python3-wstool
roscore
sudo apt install python3-roslaunch
sudo apt install ros-noetic-desktop-full
重新再启动roscore就可以正常启动了。
打开三个终端分别输入以下:
roscore
rosrun turtlesim turtlesim_node
rosrun turtlesim turtle_teleop_key