ubuntu18.04 安装 ros melodic

1.获取源

sudo sh -c 'echo "deb http://packages.ros.org/ros/ubuntu $(lsb_release -sc) main" > /etc/apt/sources.list.d/ros-latest.list'
  1. 获取公钥
sudo apt-key adv --keyserver hkp://ha.pool.sks-keyservers.net:80 --recv-key 421C365BD9FF1F717815A3895523BAEEB01FA116
sudo apt-get update

可能遇到gpg报错,添加密钥再次更新资源库

sudo apt-key adv --keyserver keyserver.ubuntu.com --recv-keys F42ED6FBAB17C654
sudo apt-get update

3.安装依赖项

sudo apt install libvtk6-jni libvtk6-java libvtk6-dev libvtk6-qt-dev libpcl-dev
sudo apt install ros-melodic-pcl-conversions ros-melodic-pcl-ros ros-melodic-perception-pcl ros-melodic-perception
  1. 安装ros-melodic
sudo apt-get install ros-melodic-desktop-full

5.进行ros初始化,需要使用python2.7

sudo rosdep init

error:Command ‘rosdep’ not found
现在python默认python3.5,切换为python2.7:

sudo apt install python-rosdep2
sudo rosdep init
#error:ImportError: No module named 'rosdep2'
update-alternatives --list python 
#/usr/bin/python2
#/usr/bin/python2.7
#/usr/bin/python3.5
sudo update-alternatives --config python
#choose python2.7
sudo rosdep init
rosdep update

可能出现报错,网不好,多试几次就好了

“rosdep init”可能报错:
error:~$ 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.

#打开hosts文件
sudo gedit /etc/hosts
#在文件末尾添加
151.101.84.133 raw.githubusercontent.com
#保存后退出再尝试

6.配置环境变量

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

7.查看ros

env | grep ROS 
  1. 测试
roscore  #启动ros

重新开一个terminal,唤醒小海龟:

rosrun turtlesim turtlesim_node

成功

你可能感兴趣的:(ROS)