1、首先设置软件源(任选其一使用)
1)国外的软件源(速度慢)
sudo sh -c 'echo "deb http://packages.ros.org/ros/ubuntu $(lsb_release -sc) main" > /etc/apt/sources.list.d/ros-latest.list'
2)国内的(速度快)
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'
3)清华源(速度快)
sudo sh -c '. /etc/lsb-release && echo "deb http://mirrors.tuna.tsinghua.edu.cn/ros/ubuntu/ $DISTRIB_CODENAME main" > /etc/apt/sources.list.d/ros-latest.list'
这里只针对ROS的下载源,想要更改全部软件源,可以百度
## 2、更新软件源
sudo apt-get update
3、设置秘钥
sudo apt-key adv --keyserver keyserver.ubuntu.com --recv-keys F42ED6FBAB17C654
4、安装
sudo apt-get install ros-melodic-desktop-full
sudo apt-get install ros-melodic-rqt*
5、初始化
sudo rosdep init
错误提示:sudo: rosdep:找不到命令
原因:python-rosdep这个包没有装
解决:安装python-rosdep
sudo apt-get install python-rosdep
继续执行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.
解决:
cd /etc
sudo gedit hosts
在末尾添加:
151.101.84.133 raw.githubusercontent.com
保存退出
继续执行sudo rosdep init
6、rosdep更新(此处问题最艰难)
rosdep update
报错:
`ERROR: unable to process source [https://raw.githubusercontent.com/ros/rosdistro/master/rosdep/ruby.yaml]:`
<urlopen error timed out>
解决办法:
0)反复执行,总会成功
1)多数人是网络的原因 ,换成手机热点,多执行几遍此命令(成功几率最大)
2)若1不可行,进入
https://site.ip138.com/raw.githubusercontent.com/
查询raw.githubusercontent.com最新IP,将/etc/hosts中的IP改成最新IP,再次反复多次执行几遍。(此方法也可以用于上一步报错)
3)若上述方法不可行,更改 /usr/lib/python2.7/dist-packages/rosdep2/下的三个文件sources_list.py、gbpdistro_support.py、rep3.py
中的DOWNLOAD_TIMEOUT = 15.0
值,改大一点就可以了。
sudo vim /usr/lib/python2.7/dist-packages/rosdep2/gbpdistro_support.py
sudo vim /usr/lib/python2.7/dist-packages/rosdep2/sources_list.py
sudo vim /usr/lib/python2.7/dist-packages/rosdep2/rep3.py
这个修改过后只是成功的几率会高很多,并非一定能成功。
4)终极解决办法:
直接手动添加需要的文件,文件链接:
链接:https://pan.baidu.com/s/1h_ZbSm2LaKv9A77DNAqE6A 提取码:kcn5
复制这段内容后打开百度网盘手机App,操作更方便哦
改 host 和 nameserver 具体内容省略
sudo gedit /etc/hosts
sudo gedit /etc/resolv.conf
在该文件夹内右键打开命令行
sudo cp -r ../ros_github/ /etc/ros/
sudo gedit /etc/ros/rosdep/sources.list.d/20-default.list
下面是修改后的 20-default.list 可直接覆盖粘贴,为了简洁,注释全删了。
yaml file:///etc/ros/ros_github/osx-homebrew.yaml osx
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
最后修改 python 初始化文件中的路径指向,修改
DEFAULT_INDEX_URL
sudo gedit /usr/lib/python2.7/dist-packages/rosdistro/__init__.py
修改 DEFAULT_INDEX_URL
DEFAULT_INDEX_URL = 'file:///etc/ros/ros_github/index-v4.yaml'
再次运行 rosdep update
成功!!!
详细可参考博文:
https://blog.csdn.net/sinat_25923849/article/details/107976434?spm=1001.2014.3001.5501
7、添加ros环境变量
echo "source /opt/ros/melodic/setup.bash" >> ~/.bashrc
source ~/.bashrc
8、安装rosinstall
sudo apt install python-rosinstall python-rosinstall-generator python-wstool build-essential
安装完成
9、运行roscore
roscore
至此已安装完成!!!