终端输入
sudo sh -c 'echo "deb http://packages.ros.org/ros/ubuntu $(lsb_release -sc) 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-noetic-desktop-full
桌面完整版安装成功
终端输入
sudo rosdep init
20.04终端输入
sudo apt install python3-rosdep2
18.04终端输入
sudo apt install python-rosdep2
然后再次初始化rosdep
sudo rosdep init
终端输入
sudo rm /etc/ros/rosdep/sources.list.d/20-default.list
再次sudo rosdep init
如果多次尝试还是不行可尝试下边方法
sudo gedit /etc/hosts
在文件末尾添加下面这段:
151.101.84.133 raw.githubusercontent.com
然后保存退出再次sudo rosdep init如果还是不行登陆IPAdress网站The Best IP Address, Email and Networking Tools - IPAddress.com,输入raw.githubusercontent.com查询到真实IP地址:
将查询到的IP替换上面代码的 151.101.84.133然后再次sudo rosdep init一般就会成功了
终端依次输入
cd /etc/ros/rosdep/sources.list.d
sudo touch 20-default.list
然后打开20-default.list添加内容
终端输入
sudo gedit 20-default.list
打开sudo gedit 20-default.list 后将下面内容添加到20-default.list 中然后Ctrl+S 保存退出进入第六步
# os-specific listings first
yaml https://raw.githubusercontent.com/ros/rosdistro/master/rosdep/osx-homebrew.yaml osx
# generic
yaml https://raw.githubusercontent.com/ros/rosdistro/master/rosdep/base.yaml
yaml https://raw.githubusercontent.com/ros/rosdistro/master/rosdep/python.yaml
yaml https://raw.githubusercontent.com/ros/rosdistro/master/rosdep/ruby.yaml
gbpdistro https://raw.githubusercontent.com/ros/rosdistro/master/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
多次尝试依然报错可尝试下面的解决方法
1.把相关文件下载到本地:(注意:下面代码中nice换为你的用户名)
git clone https://github.com/ros/rosdistro.git /home/nice/robot
如网络不好无法Git下载可以在下面我分享的百度网盘链接下载压缩包然后解压提取到主目录下
链接:https://pan.baidu.com/s/1ZjMcvqOvLRa_iTdXis8ufg
提取码:01e2
2.改去rosdep update获取文件的网址换为本地地址:
终端输入(注意:下面代码以Ubuntu20.04为例,18.04将下面代码中python3改为python2.7即可)
sudo gedit /usr/lib/python3/dist-packages/rosdep2/rep3.py
输入后回车会弹出rep3.py文件将原来文件中的 REP3_TARGETS_URL = 'https://raw.githubusercontent.com/ros/rosdistro/master/releases/targets.yaml' 替换成 REP3_TARGETS_URL = 'file:///home/nice/robot/releases/targets.yaml'(此处nice改为你的用户名因为此处的具体地址为你下载到本地的文件的地址。)
Ctrl+S保存并退出
终端输入(注意:下面代码以Ubuntu20.04为例,18.04将下面代码中python3改为python2.7即可)
sudo gedit /usr/lib/python3/dist-packages/rosdistro/__init__.py
输入回车后会弹出__init__.py文件将原来文件中的 DEFAULT_INDEX_URL = 'https://raw.githubusercontent.com/ros/rosdistro/master/index-v4.yaml'替换成 DEFAULT_INDEX_URL = 'file:///home/nice/robot/index-v4.yaml'(此处nice改为你的用户名因为此处的具体地址为你下载到本地的文件的地址。)
3.修改/etc/ros/rosdep/sources.list.d/20-default.list中的网址为本地地址
终端输入
sudo gedit /etc/ros/rosdep/sources.list.d/20-default.list
输入回车后会弹出20-default.list文件将原来文件中的所有 raw.githubusercontent.com开头的网址替换成对应文件在本地的路径(可将下面代码更换20-default.list中的代码注意:代码中的nice全部更换为你的用户名)
# os-specific listings first
yaml file:///home/nice/robot/rosdep/osx-homebrew.yaml osx
# generic
yaml file:///home/nice/robot/rosdep/base.yaml
yaml file:///home/nice/robot/rosdep/python.yaml
yaml file:///home/nice/robot/rosdep/ruby.yaml
gbpdistro file:///home/nice/robot/releases/fuerte.yaml fuerte
# newer distributions (Groovy, Hydro, ...) must not be listed anymore, they are being fetched from the rosdistro index.yaml instead
修改为如下图后保存退出(注意:代码中的nice全部更换为你的用户名)
然后再次rosdep update一般99%几率成功,如果不成功可评论或私信我
rosdep update成功
终端输入(下面代码以20.04为例18.04将下面代码中noetic改为melodic即可)
echo "source /opt/ros/noetic/setup.bash" >> ~/.bashrc
然后终端输入
source ~/.bashrc
20.04终端输入
sudo apt install python3-rosinstall python3-rosinstall-generator python3-wstool build-essential
18.04终端输入
sudo apt install python-rosinstall python-rosinstall-generator python-wstool build-essential
Ctrl+Alt+T新建一个终端输入
roscore
出现错误Command 'roscore' not found,
20.04终端输入
sudo apt install ros-noetic-desktop-full
18.04终端输入
sudo apt install ros-melodic-desktop-full
roscore运行成功界面