sudo sh -c '. /etc/lsb-release && echo "deb http://mirrors.ustc.edu.cn/ros/ubuntu/ `lsb_release -cs` main" > /etc/apt/sources.list.d/ros-latest.list'
sudo apt-key adv --keyserver 'hkp://keyserver.ubuntu.com:80' --recv-key C1CF6E31E6BADE8868B172B4F42ED6FBAB17C654
sudo apt update
在终端输入以下命令后回车
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
sudo chmod 777 /etc
sudo rosdep init
报错:
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.
sudo gedit /etc/hosts
把下面这些地址拷贝到hosts文件末尾,然后保存。
192.30.253.118 gist.github.com
185.199.110.153 github.io
151.101.113.194 github.global.ssl.fastly.net
52.216.227.168 github-cloud.s3.amazonaws.com
52.74.223.119 github.com
199.232.28.133 avatars1.githubusercontent.com
199.232.28.133 avatars2.githubusercontent.com
199.232.28.133 avatars0.githubusercontent.com
199.232.28.133 avatars3.githubusercontent.com
199.232.28.133 raw.githubusercontent.com
199.232.28.133 user-images.githubusercontent.com
199.232.28.133 avatars.githubusercontent.com
199.232.28.133 github.map.fastly.net
199.232.28.133 avatars7.githubusercontent.com
54.239.31.69 aws.amazon.com
54.239.30.25 console.aws.amazon.com
54.239.96.90 ap-northeast-1.console.aws.amazon.com
54.240.226.81 ap-southeast-1.console.aws.amazon.com
54.240.193.125 ap-southeast-2.console.aws.amazon.com
54.239.54.102 eu-central-1.console.aws.amazon.com
177.72.244.194 sa-east-1.console.aws.amazon.com
176.32.114.59 eu-west-1.console.aws.amazon.com
54.239.31.128 us-west-1.console.aws.amazon.com
54.240.254.230 us-west-2.console.aws.amazon.com
54.239.38.102 s3-console-us-standard.console.aws.amazon.com
54.231.49.3 s3.amazonaws.com
52.219.0.4 s3-ap-northeast-1.amazonaws.com
54.231.242.170 s3-ap-southeast-1.amazonaws.com
54.231.251.21 s3-ap-southeast-2.amazonaws.com
54.231.193.37 s3-eu-central-1.amazonaws.com
52.218.16.140 s3-eu-west-1.amazonaws.com
52.92.72.2 s3-sa-east-1.amazonaws.com
54.231.236.6 s3-us-west-1.amazonaws.com
54.231.168.160 s3-us-west-2.amazonaws.com
52.216.80.48 github-cloud.s3.amazonaws.com
54.231.40.3 github-com.s3.amazonaws.com
52.216.20.171 github-production-release-asset-2e65be.s3.amazonaws.com
52.216.228.168 github-production-user-asset-6210df.s3.amazonaws.com
执行sudo gedit /etc/resolv.conf,将原有的nameserver这一行注释,并添加以下两行:
sudo gedit /etc/resolv.conf
nameserver 8.8.8.8 #google域名服务器
nameserver 8.8.4.4 #google域名服务器
再次执行sudo rosdep init,这次会报一个问题,就是文件已存在:
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,我至今操作过很多次,没有出现不成功的状态,如果实在不成功,试试换手机热点,多执行几次,最后输出如下信息就OK了:
sudo rm /etc/ros/rosdep/sources.list.d/20-default.list
sudo rosdep init
显示如下信息,则rosdep初始化成功
wrote /etc/ros/rosdep/sources.list.d/20-default.list
Recommended: please run
rosdep update
常见报错信息就是各种The read operation timed out.。
解决,直接从对应网址保存所有需要的文件,然后把网络路径改成本地文件路径:
链接: https://pan.baidu.com/s/1JGFlI0hYo6tVEicQXnSj7w
提取码: xiao
下载所有的文件,整理好文件夹,对于主要的yaml文件的路径都在20-default.list这个里面有,基本套路
就是https://raw.githubusercontent.com/ros/rosdistro/master/XXX后面的xxx根据不同文件替换一下,
打开index-v4.yaml能看到所有需要的其他子文件夹,yaml文件和gz 压缩包:
1:将下载的文件夹移动到etc/ros/ros_github/为你自己提取安放的路径
直接输进浏览器地址栏,都能直接打开对应的yaml和.gz文件,ctrl+s保存即可,最后形成这么一个文件夹,文件夹的名字自己随便起都可以,里面的子文件夹一定和index-v4.yaml保持一致,如下图所示(我整理好了,大家也可以直接用)。
修改 index-v4.yaml的路径和20-default.list文件里面的路径:
sudo gedit /usr/lib/python2.7/dist-packages/rosdistro/__init__.py
比如我最后放那些yaml的文件夹放在/etc/ros/ros_github,将网址地址改为file:///etc/ros/ros_github/index-v4.yaml如下图所示
2:修改 /etc/ros/rosdep/sources.list.d/20-default.list文件。
sudo gedit /etc/ros/rosdep/sources.list.d/20-default.list
把里面指向网址的路径改为本地,比如我最后放那些yaml的文件夹放在/etc/ros/ros_github,
# os-specific listings first
yaml file:///etc/ros/ros_github/osx-homebrew.yaml osx
# generic
yaml file:///etc/ros/ros_github/base.yaml
yaml file:///etc/ros/ros_github/python.yaml
yaml file:///etc/ros/ros_github/ruby.yaml
gbpdistro file:///etc/ros/ros_github/fuerte.yaml fuerte
# newer distributions (Groovy, Hydro, ...) must not be listed anymore, they are being fetched from the rosdistro index.yaml instead
3:再次执行rosdep update命令
检查安装情况:运行小海龟和rviz
建议再执行以下环境配置命令(有的同学可能漏了,且再来一次无妨):
echo "source /opt/ros/melodic/setup.bash" >> ~/.bashrc
source ~/.bashrc
4:再次执行
rosdep update
如过报错,则从新开一个命令框进行更新
1.终端输入命令回车:
roscore
出现以上提示则代表安装成功。
2.检查基础功能
在终端成功输入roscore后,开启第二个终端输入
rosrun turtlesim turtlesim_node
3:会出现一个小海龟,最后开启第三个终端输入
rosrun turtlesim turtle_teleop_key
参考:https://blog.csdn.net/sinat_25923849/article/details/107976434