Ubuntu18.04安装ros melodic
目前认为比较稳定的安装方案,无需翻墙。 ——BITFSD
换源(系统源)
意义:Ubuntu默认源的服务器在国外,由于相关法律法规的限制,大陆对国外服务器的访问速率极慢,因此需要采用国内的镜像源进行替代。经过多次尝试,我们推荐使用中科大源
1
sudo gedit /etc/apt/sources.list
这一句指令会要求输入密码,Linux系统的保密措施使得键盘的输入不会在终端里显示
gedit
是一个文本软件,相当于Windows系统的记事本将以下内容复制进刚才打开的文本框里,删除文本框里原有的一大堆东西
1
2
3
4
5
6
7
8
9
10deb https://mirrors.ustc.edu.cn/ubuntu/ bionic main restricted universe multiverse
deb https://mirrors.ustc.edu.cn/ubuntu/ bionic-updates main restricted universe multiverse
deb https://mirrors.ustc.edu.cn/ubuntu/ bionic-backports main restricted universe multiverse
deb https://mirrors.ustc.edu.cn/ubuntu/ bionic-security main restricted universe multiverse
deb https://mirrors.ustc.edu.cn/ubuntu/ bionic-proposed main restricted universe multiverse
deb-src https://mirrors.ustc.edu.cn/ubuntu/ bionic main restricted universe multiverse
deb-src https://mirrors.ustc.edu.cn/ubuntu/ bionic-updates main restricted universe multiverse
deb-src https://mirrors.ustc.edu.cn/ubuntu/ bionic-backports main restricted universe multiverse
deb-src https://mirrors.ustc.edu.cn/ubuntu/ bionic-security main restricted universe multiverse
deb-src https://mirrors.ustc.edu.cn/ubuntu/ bionic-proposed main restricted universe multiverse完成上述步骤后,在终端内输入:
1
2sudo apt-get update
sudo apt-get upgrade再次执行例如
sudo apt-get install
等命令时发现下载速率有了极大提升
安装ros
以下内容可参考ros官网
选择下载源(ros源),我们仍然推荐使用中科大源
1
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'
设置密匙
1
2sudo apt install curl # if you haven't already installed curl
curl -s https://raw.githubusercontent.com/ros/rosdistro/master/ros.asc | sudo apt-key add -更新源
1
sudo apt-get update
安装ros-desktop
1
sudo apt-get install ros-melodic-desktop-full
这一步结束后并不代表ros安装完成
设置环境变量
1
2echo "source /opt/ros/melodic/setup.bash" >> ~/.bashrc
source ~/.bashrc.bashrc
文件中保存的环境变量在每次开启终端的时候会自动加载入新终端内,若要手动刷新,可使用source ~/.bashrc
命令,~
符号代表主目录若使用主题,比如zsh主题(可以美化终端),则运行
1
2echo "source /opt/ros/melodic/setup.zsh" >> ~/.zshrc
source ~/.zshrc准备依赖包
1
sudo apt install python-rosdep python-rosinstall python-rosinstall-generator python-wstool build-essential
初始化rosdep
1
2
3sudo apt install python-rosdep
sudo rosdep init
rosdep update不出意外在运行前两个命令后,第三个命令会运行失败,终端报错显示超时,这是因为
rosdep update
命令会请求远程服务器,而这个服务器位于国外,所以,我们对默认的地址进行修改,采用国内的镜像进行替代
修改
20-default.list
1
2cd /etc/ros/rosdep/sources.list.d
sudo gedit 20-default.list将内容替换为:
1
2
3
4
5
6
7
8
9
10# os-specific listings first rosdep update
yaml https://gitee.com/wybros/rosdistro/raw/master/rosdep/osx-homebrew.yaml osx
# generic
yaml https://gitee.com/wybros/rosdistro/raw/master/rosdep/base.yaml
yaml https://gitee.com/wybros/rosdistro/raw/master/rosdep/python.yaml
yaml https://gitee.com/wybros/rosdistro/raw/master/rosdep/ruby.yaml
gbpdistro https://gitee.com/wybros/rosdistro/raw/master/releases/fuerte.yaml fuerte
# newer distributions (Groovy, Hydro, ...) must not be listed anymore, they are being fetched from the rosdistro index.yaml instead修改
gbpdistro_support.py
1
2cd /usr/lib/python2.7/dist-packages/rosdep2/
sudo gedit gbpdistro_support.py将里面所有的
raw.githubusercontent.com/ros/rosdistro/master
替换成gitee.com/wybros/rosdistro/raw/master
修改
rep3.py
1
2cd /usr/lib/python2.7/dist-packages/rosdep2/
sudo gedit rep3.py将里面所有的
raw.githubusercontent.com/ros/rosdistro/master
替换成gitee.com/wybros/rosdistro/raw/master
修改
sources_list.py
1
2cd /usr/lib/python2.7/dist-packages/rosdep2/
sudo gedit sources_list.py将里面所有的
raw.githubusercontent.com/ros/rosdistro/master
替换成gitee.com/wybros/rosdistro/raw/master
修改
__init__.py
1
2cd /usr/lib/python2.7/dist-packages/rosdistro/
sudo gedit __init__.py将里面所有的
raw.githubusercontent.com/ros/rosdistro/master
替换成gitee.com/wybros/rosdistro/raw/master
- 最后再次执行
rosdep update
,等待片刻即可安装成功
验证
- 新建终端,输入
roscore
,无报错
我是学生,给我钱