目录
1 更改Ubuntu软件源:
打开软件和更新,将下载源设为清华源:
2 设置软件源
清华源:
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'
别的源可参考link
3 设置密钥
sudo apt-key adv --keyserver keyserver.ubuntu.com --recv-keys F42ED6FBAB17C654
4 安装过程及问题解决
4.1 安装
sudo apt-get update
sudo apt-get install ros-melodic-desktop-full
sudo apt-get install ros-melodic-rqt*
4.2 初始化
sudo rosdep init
未报错得话跳过4.2.1
4.2.1 初始化过程报错
报错:
sudo: rosdep:找不到命令
这里网上大部分教程是让sudo apt install python-rosdep2
但是这样会将一些包卸载掉,本人这样操作下去会遇到新的问题,所以不采取该方法。
分析原因:python-rosdep这个包没有装
解决方法:安装python-rosdep sudo apt-get install python-rosdep
重新初始化:sudo rosdep init
报错:
pkg_resources.DistributionNotFound: The ‘rosdep==0.20.1’ distribution was not found and is required by the application
这里需要更改我们ubuntu得默认python版本:
1.列出所有可用python替代版本信息:update-alternatives --list python
2.查看系统中的python信息:ls /usr/bin/python*
3.将python2.7和python3.6添加到候选
sudo update-alternatives --install /usr/bin/python python /usr/bin/python2.7 1
sudo update-alternatives --install /usr/bin/python python /usr/bin/python3.6 2
4.再次查看 sudo update-alternatives --config python
并将python2.7设为当前值
重新初始化:sudo rosdep init
4.3 更新
rosdep update
若报错:
ERROR: error loading sources list: (‘The read operation timed out’,)
网络连接问题需要挂vpn,自己解决
4.4 安装rosinstall
sudo apt-get install python-rosinstall
4.5 加载环境设置文件
source /opt/ros/melodic/setup.bash
4.6 创建并初始化工作目录
mkdir -p ~/catkin_ws/src
cd ~/catkin_ws/src
catkin_init_workspace
cd ~/catkin_ws/
catkin_make
4.7 设置环境变量
sudo apt install net-tools
gedit ~/.bashrc
将下面内容写入到文件最后:
#Set ROS melodic
source /opt/ros/melodic/setup.bash
source ~/catkin_ws/devel/setup.bash
# Set ROS Network#ifconfig查看你的电脑ip地址
export ROS_HOSTNAME=172.17.0.1
export ROS_MASTER_URI=http://${ROS_HOSTNAME}:11311
# Set ROS alias command 快捷指令
alias cw='cd ~/catkin_ws'
alias cs='cd ~/catkin_ws/src'
alias cm='cd ~/catkin_ws && catkin_make'
5 测试
roscore
rosrun turtlesim turtlesim_node
rosrun turtlesim turtle_teleop_key
参考:
ubuntu18.04安装ROS Melodic(最详细配置)
基于Ubuntu18.04的ROS Melodic环境详细配置(含各种大坑及填坑)
安装ROS时执行到sudo rosdep init
sudo rosdep init出错的解决方案