本教程将手把手教你如何在 Ubuntu 20.04 和 Ubuntu 22.04 上安装 ROS(机器人操作系统)及其经典仿真工具 Gazebo。无论你是机器人初学者还是开发者,通过这篇教程都能顺利完成环境搭建。文章涵盖 ROS安装、Gazebo仿真 以及针对不同 Ubuntu 版本的详细步骤,确保你轻松上手。
打开终端(Ctrl+Alt+T),执行以下命令更新软件包列表并升级现有软件:
sudo apt updatesudo apt upgrade -y
确保系统已经安装了 curl、wget 等工具,若没有则安装:
sudo apt install curl wget gnupg2 lsb-release -y
不同 Ubuntu 版本对应不同的 ROS 版本:
请根据你的系统选择下方对应的安装步骤。注意关键词 Ubuntu 20.04 和 Ubuntu 22.04 将贯穿全文,帮助你快速定位。
sudo sh -c "echo "deb http://packages.ros.org/ros/ubuntu $(lsb_release -sc) main" > /etc/apt/sources.list.d/ros-latest.list"
curl -s https://raw.githubusercontent.com/ros/rosdistro/master/ros.asc | sudo apt-key add -
sudo apt updatesudo apt install ros-noetic-desktop-full -y
此过程会一并安装 Gazebo 9(ROS Noetic 默认附带)。如需最新 Gazebo 11,可单独安装:
sudo apt install gazebo11 libgazebo11-dev -y
echo "source /opt/ros/noetic/setup.bash" >> ~/.bashrcsource ~/.bashrc
sudo apt install python3-rosdep python3-rosinstall python3-rosinstall-generator python3-wstool build-essential -ysudo rosdep initrosdep update
启动 ROS 核心:
roscore
新开终端启动 turtlesim:
rosrun turtlesim turtlesim_node
再开终端控制乌龟:
rosrun turtlesim turtle_teleop_key
测试 Gazebo:终端输入 gazebo 应打开仿真窗口。
sudo apt update && sudo apt install curl gnupg lsb-releasesudo curl -sSL https://raw.githubusercontent.com/ros/rosdistro/master/ros.key -o /usr/share/keyrings/ros-archive-keyring.gpgecho "deb [arch=$(dpkg --print-architecture) signed-by=/usr/share/keyrings/ros-archive-keyring.gpg] http://packages.ros.org/ros2/ubuntu $(lsb_release -cs) main" | sudo tee /etc/apt/sources.list.d/ros2.list > /dev/null
sudo apt updatesudo apt install ros-humble-desktop -y
ROS2 Humble 官方推荐使用 Gazebo Fortress,可通过以下命令安装:
sudo apt install ros-humble-ros-gz -y
该包会自动安装 Gazebo Fortress 及相关桥接包。也可单独安装 Gazebo:
sudo apt install gz-fortress -y
echo "source /opt/ros/humble/setup.bash" >> ~/.bashrcsource ~/.bashrc
sudo apt install python3-colcon-common-extensions python3-rosdep python3-vcstool -ysudo rosdep initrosdep update
启动一个 talker 和 listener 测试 ROS2:
ros2 run demo_nodes_cpp talker# 新终端ros2 run demo_nodes_py listener
测试 Gazebo:终端输入 gz sim 应打开仿真窗口,或 ign gazebo(旧命令)。
sudo apt --fix-broken install。source ~/.bashrc 或重新登录终端。export LIBGL_ALWAYS_SOFTWARE=1 软件渲染。至此,你已经成功在 Ubuntu 20.04 或 Ubuntu 22.04 上完成了 ROS安装 和 Gazebo仿真 环境的搭建!现在可以开始你的机器人编程之旅了。如有疑问,欢迎在评论区交流。
本文由主机测评网于2026-02-27发表在主机测评网_免费VPS_免费云服务器_免费独立服务器,如有疑问,请联系我们。
本文链接:https://vpshk.cn/20260227527.html