这里我们使用的虚拟机软件为VMware Workstation 15 Player
下载地址:https://www.vmware.com/cn/products/workstation-player/workstation-player-evaluation.html
Ubuntu:https://ubuntu.com/download
这里我们下载的长期支持版Ubuntu 18.04
打开VMware Workstations 15 Player,选择创建新虚拟机
选择安装程序光盘映像文件(iso),通过浏览载入我们之前下载的Ubuntu18.04的镜像文件
输入安装信息
配置虚拟机名称及虚拟机位置
选择虚拟机硬盘大小,这里选择30G,选择将虚拟磁盘存储为单个文件
在自定义硬件中可配置虚拟机内存大小、处理器数等信息,该信息也可之后虚拟机运行前进行配置更改,点击完成,系统会进行自动安装,耐心等待即可。
在安装软件之前,为了提升下载速度,我们先将Ubuntu的软件源改为国内的镜像。
打开终端,首先备份原文件,输入命令:
sudo mv /etc/apt/sources.list /etc/apt/sources.list.backup
添加国内源
sudo gedit /etc/apt/sources.list
在打开的编辑器中输入
#清华源
deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ bionic main restricted universe multiverse
deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ bionic-updates main restricted universe multiverse
deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ bionic-backports main restricted universe multiverse
deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ bionic-security main restricted universe multiverse
deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ bionic-proposed main restricted universe multiverse
#deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ bionic main restricted universe multiverse
#deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ bionic-updates main restricted universe multiverse
#deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ bionic-backports main restricted universe multiverse
#deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ bionic-security main restricted universe multiverse
#deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ bionic-proposed main restricted universe multiverse
这里我们选择的清华源
国内还有其他好的源,如中科大源、阿里云源等,选择其中一个就好
中科大源
deb 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
阿里云源
deb http://mirrors.aliyun.com/ubuntu/ bionic main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ bionic-security main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ bionic-updates main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ bionic-proposed main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ bionic-backports main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ bionic main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ bionic-security main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ bionic-updates main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ bionic-proposed main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ bionic-backports main restricted universe multiverse
保存更改之后,在终端输入命令,更新列表
sudo apt-get update
考虑到长期支持性,我们选择ROS Melodic版本安装,安装具体步骤可参见 ROS Wiki上的Ubuntu install of ROS Melodic
确认Ubuntu的软件库设置,允许 “restricted”,“universe” 和"multiverse"。在之前软件源设置的时候,都是包含的;
sudo sh -c '. /etc/lsb-release && echo "deb http://mirrors.tuna.tsinghua.edu.cn/ros/ubuntu/ `lsb_release -cs` main" > /etc/apt/sources.list.d/ros-latest.list'
这里用的也是清华的镜像。
sudo apt-key adv --keyserver 'hkp://keyserver.ubuntu.com:80' --recv-key C1CF6E31E6BADE8868B172B4F42ED6FBAB17C654
首先确认软件包是最新的
sudo apt update
然后,安装完整桌面版的ros
sudo apt install ros-melodic-desktop-full
完成后,可通过以下命令查看安装的ros包
apt search ros-melodic
rosdep能够使你轻松安装系统所需的且需要编译的源码,同时rosdep也是ROS系统中某些核心组件运行所必须的。
sudo rosdep init
rosdep update
echo "source /opt/ros/melodic/setup.bash" >> ~/.bashrc
source ~/.bashrc
sudo apt install python-rosinstall python-rosinstall-generator python-wstool build-essential
为了查看ros是否安装成功,可运行一下例子进行测试。
roscore
2. 下面我们运行一个小例子
再打开一个终端,输入命令,可以看到弹出了一个小乌龟的窗口
rosrun turtlesim turtlesim_node
再打开一个终端,输入命令后,我们可以通过键盘方向键来控制乌龟运动。
rosrun turtlesim turtle_teleop_key
在运行命令rosdep update
时,经常以下类似的报错:
ERROR: unable to process source [https://raw.githubusercontent.com/ros/rosdistro/master/rosdep/base.yaml]:
(https://raw.githubusercontent.com/ros/rosdistro/master/rosdep/base.yaml)
通过网上搜索,主要是网络的原因,简单的处理办法是采用手机热点连接,亲测有效。
在刚连上手机热点,运行rosdep update
会报以下类似错
ERROR: unable to process source [https://raw.githubusercontent.com/ros/rosdistro/master/rosdep/osx-homebrew.yaml]:
(https://raw.githubusercontent.com/ros/rosdistro/master/rosdep/osx-homebrew.yaml)
可通过以下步骤处理:
首先,删除rosdep源文件
sudo rm /etc/ros/rosdep/sources.list.d/20-default.list
在重新运行初始化指令
sudo rosdep init
rosdep update