Ubuntu18.04安装ROS(melodic)

1.安装源(选国内的源,此处为中科大的源)

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'

2.设置key

sudo apt-key adv --keyserver 'hkp://keyserver.ubuntu.com:80' --recv-key C1CF6E31E6BADE8868B172B4F42ED6FBAB17C654

3.更新

sudo apt-get update

4.安装完整版

sudo apt-get install ros-melodic-desktop-full 
sudo apt install python-rosdep python-rosinstall python-rosinstall-generator python-wstool build-essential

5.解决依赖问题

sudo rosdep init
rosdep update

到这部由于国内网络原因,一般都会被墙,导致更新失败,这里提供一种本地更新的方式,供大家参考
(1)将rosdistro clone到本地

git clone https://github.com/ros/rosdistro.git

如果下载不下来,可以通过百度网盘的方式下载,链接:

链接:https://pan.baidu.com/s/1qrXdrG5FAp0LLwXkglPO5g
提取码:5x76

可以直接保存到/home/yourname/rosdistro
(2)替换4个文件的路径
替换时,所有的yourname都要替换成自己的用户名!
第一个文件:

cd /home/yourname/rosdistro/rosdep/sources.list.d/
sudo gedit 20-default.list 

将里面所有的 raw.githubusercontent.com
替换成自己的地址,如下

# os-specific listings first
yaml file:///home/yourname/rosdistro/rosdep/osx-homebrew.yaml osx

# generic
yaml file:///home/yourname/rosdistro/rosdep/base.yaml
yaml file:///home/yourname/rosdistro/rosdep/python.yaml
yaml file:///home/yourname/rosdistro/rosdep/ruby.yaml
gbpdistro file:///home/yourname/rosdistro/releases/fuerte.yaml fuerte

# newer distributions (Groovy, Hydro, ...) must not be listed anymore, they are being fetched from the rosdistro index.yaml instead

第二个文件:

cd /usr/lib/python2.7/dist-packages/rosdep2/
sudo gedit gbpdistro_support.py

同样进行替换:

FUERTE_GBPDISTRO_URL = 'file:///home/yourname/rosdistro/' \
    'releases/fuerte.yaml'

第三个文件:

cd /usr/lib/python2.7/dist-packages/rosdep2/
sudo gedit rep3.py

同样进行替换:

REP3_TARGETS_URL = 'file:///home/yourname/rosdistro/releases/targets.yaml'

第四个文件:

cd /usr/lib/python2.7/dist-packages/rosdistro/
sudo gedit __init__.py
(我的电脑里是 __init__.py,但是原作者的是init.py,大家可以自己查看)

同样的替换:

DEFAULT_INDEX_URL = 'file:///home/yourname/rosdistro/index-v4.yaml'

(3)打开一个终端,执行以下指令创建root并切换至root用户

sudo su //输入你的密码切换至root
sudo mkdir -p /etc/ros/rosdep/sources.list.d   
cd /etc/ros/rosdep/sources.list.d
sudo gedit 20-default.list

将以下内容复制进去,同时别忘了更改用户名:

#os-specific listings first
yaml file:///home/yourname/rosdistro/rosdep/osx-homebrew.yaml osx
#generic
yaml file:///home/yourname/rosdistro/rosdep/base.yaml
yaml file:///home/yourname/rosdistro/rosdep/python.yaml
yaml file:///home/yourname/rosdistro/rosdep/ruby.yaml
gbpdistro file:///home/yourname/rosdistro/releases/fuerte.yaml fuerte

#newer distributions (Groovy, Hydro, ...) must not be listed anymore, they are being fetched from the rosdistro index.yaml instead

最后打开新终端
执行:rosdep update即可成功!
6.设置环境变量

echo "source /opt/ros/melodic/setup.bash" >> ~/.bashrc
source ~/.bashrc

7.测试
打开新终端,输入roscore,若出现以下的内容,说明安装成功:

 .. logging to /home/ubuntu/.ros/log/cb38e680-dee2-11ea-bae1-70665563e003/roslaunch-nx-1205.log
Checking log directory for disk usage. This may take a while.
Press Ctrl-C to interrupt
Done checking log file disk usage. Usage is <1GB.

started roslaunch server http://nx:36773/
ros_comm version 1.14.7


SUMMARY
========

PARAMETERS
 * /rosdistro: melodic
 * /rosversion: 1.14.7

NODES

auto-starting new master
process[master]: started with pid [1215]
ROS_MASTER_URI=http://nx:11311/

setting /run_id to cb38e680-dee2-11ea-bae1-70665563e003
process[rosout-1]: started with pid [1228]
started core service [/rosout]

到此ROS(melodic版)就安装成功了!
文章参考:

https://www.ncnynl.com/archives/201906/3147.html
https://blog.csdn.net/weixin_43311920/article/details/114796748

  • 2
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值