1,首先最重要的是把系统默认的源为aliyun镜像源,否则在update的时候非常非常慢,先备份sources.list,然后编辑/etc/apt/sources.list文件
把http:
//archive
.ubuntu.com
/ubuntu都改成
http://mirrors
.aliyun.com/ubuntu
cd /etc/apt
sudo cp sources.list sources_old.list
2,添加ROS软件源
国外源:
sudo sh -c 'echo ''deb http://packages.ros.org/ros/ubuntu $(lsb_release -sc) main''> /etc/apt/sources.list.d/ros-latest.list'
国内源
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'
清华源
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'
3,安装ROS软件需要授权密钥,获取授权密钥时会报拒绝连接,所以先把域名映射加到hosts文件
进入https://site.ip138.com/输入raw.githubusercontent.com获取到香港的服务器IP为151.101.76.133
加入域名映射
sudo vim /etc/hosts
151.101.76.133 raw.githubusercontent.com
151.101.76.133 raw.github.com
4,获取密钥,会在命令当前目录下生成ros.key文件
sudo wget https://raw.githubusercontent.com/ros/rosdistro/master/ros.key
5,以上3,4步骤也可通过如下命令实现授权(不一定每次都有用)
sudo apt-key adv --keyserver hkp://ha.pool.sks-keyservers.net:80 --recv-key 421C365BD9FF1F717815A3895523BAEEB01FA116
6,用这个密钥配置 apt 软件包管理系统,注意要在用户主目录下执行(/home/username),执行后提示OK即可删除ros.key
sudo apt-key add ros.key
7,更新软件包索引
sudo apt-get update
8,ubuntu16对应版本为kinetic
sudo apt-get install ros-kinetic-desktop-full
ubuntu18对应版本为melodic
sudo apt-get install ros-melodic-desktop-full
以下是基于ubuntu16.04,除版本号不一样,其他都相同(ubuntu18把kinetic替换为melodic
)
在这一步可能会报错说依赖无法安装,则执行下面的命令
sudo apt-get install aptitude
sudo aptitude install ros-kinetic-desktop-full
选择y
9,执行ROS相关命令前要确保ROS相关环境变量已添加,避免都执行setup.basg,把"source /opt/ros/kinetic/setup.bash"写到~/.bashrc中,setup.bash会自动添加ROS相关的环境变量
echo ''source /opt/ros/kinetic/setup.bash'' >> ~/.bashrc
source ~/.bashrc
10,查看可用软件包
apt-cache search ros-kinetic
11,查看ROS的环境变量
export | grep ROS
12,初始化 rosdep,rosdep可以在我们需要编译某些源码的时候为其安装一些依赖项,同时也是某些ROS核心功能组件所必需用到的工具。在ubuntu18中执行sudo rosdep init,会提示找不到rosdep命令,要先安装rospack-tools
sudo apt install rospack-tools
sudo rosdep init
上面这一步可能回报错,pkg_resources.DistributionNotFound: The 'rosdistro>=0.7.5' distribution,解决办法为:
sudo apt install python3-catkin-pkg
sudo apt install python3-rospkg
sudo apt install python3-rosdep-modules
sudo apt install python3-rosdep
rosdep update
这个最好在用户目录下执行,不要用root用户执行
执行rosdep update过程中可能会报超时错误,换成手机热点网络,或者多尝试几次
13, 构建依赖项(dependencies for building packages),rosinstall 是一个经常使用的命令行工具,可以从一个命令下载许多个ROS包的源树。要安装这个工具和其他构建ROS包的依赖项,运行命令:
sudo apt-get install python-rosinstall python-rosinstall-generator python-wstool build-essential
14,ROS安装成功,测试启动ROS MASTER
roscore
15,打开新的终端,启动仿真器
rosrun turtlesim turtlesim_node
16,打开新终端,开启控制节点
rosrun turtlesim turtle_teleop_key
17,打开新终端,查看ROS的图形化界面
rosrun rqt_graph rqt_graph
ros卸载
sudo apt-get purge ros-*
卸载依赖
sudo apt-get autoremove