ROS安装问题: “Command ‘roscore‘ not found, but can be installed with: sudo apt install python-roslaunch“

本文记录了解决在Ubuntu18系统上安装ROS melodic后,无法运行roscore命令的问题。通过重新安装ros-melodic-desktop包并更新.bashrc文件,最终成功启动ROS。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

ROS安装问题: "Command 'roscore' not found, but can be installed with: sudo apt install python-roslaunch"

前言

VMware 15虚拟机,Ubuntu 18系统,安装 ROS melodic。安装结束之后,运行指令 “roscore”,弹出 “Command ‘roscore’ not found, but can be installed with: sudo apt install python-roslaunch” 的提示,无法启动ROS。搜索论坛,最后成功解决了该问题,解决过程如下。

问题描述

安装结束后,输入:

roscore

报错:

Command ‘roscore’ not found, but can be installed with:
sudo apt install python-roslaunch

根据提示输入: sudo apt install python-roslaunch

报错:

E: Unable to correct problems, you have held broken packages.

解决方案

由[1]可知,指令 “roscore” 之所以能够被执行,首先需要在文件夹 “/opt/ros/indigo/bin/” 里面存在名为 “roscore” 的二进制可执行文件,打开文件夹,检查文件是否存在:

cd /opt/ros/melodic/bin
ls -l

果然没有。

由[2],输入:

sudo apt-get install ros-melodic-desktop

cd 进去再看,有了!
执行

source ~/.bashrc

再次启动ROS

roscore

成功了!

在[2]中,作者首先通过 sudo apt-get install ros-melodic-desktop-full 安装了ROS的“桌面完整版”,发现缺少部分文件后,又使用 sudo apt-get install ros-melodic-desktop 安装了ROS的“桌面版”(ROS版本见[3])。我分析,他是想通过这种方式来补全缺少的文件,最后竟然成功了。他真是太机智了!

[1]. 如何解决ROS “roscore command not found”
[2]. ROS安装
[3]. ROS入门笔记(二):ROS安装与环境配置及卸载(重点)

<think>嗯,用户遇到了在Ubuntu系统中找不到'roscore'命令的问题,想要安装它。根据提供的引用资料,看起来用户可能是在安装ROS之后遇到了这个问题。首先,我需要确认'roscore'属于哪个软件包。根据引用1到5,都提到需要安装python-roslaunch包,所以安装这个包可能解决问题。 不过,用户可能已经按照ROS的官方文档安装ROS,但为什么还是缺少这个命令呢?可能的原因是没有正确安装ROS的某个组件,或者环境变量没有设置好。比如,引用5中提到需要设置ROS的环境变量,比如ROS_PACKAGE_PATH、ROS_HOSTNAME和ROS_MASTER_URI。这说明用户在安装后可能需要配置环境变量,比如通过source /opt/ros/<distro>/setup.bash。 另外,用户可能安装的是ROS的不同版本,比如melodic或noetic,而对应的安装命令可能有所不同。例如,对于Ubuntu 18.04和melodic,可能需要使用sudo apt install ros-melodic-desktop-full,而python-roslaunch可能属于不同的包。但根据引用中的建议,直接安装python-roslaunch可能有效,但需要确认是否正确。 还需要注意,用户可能误解了roscore安装方式,因为roscoreROS核心的一部分,通常通过完整安装ROS来获得。可能用户只安装了部分组件,导致缺少必要的包。因此,除了安装python-roslaunch外,还需要检查是否完整安装ROS。 另外,用户可能没有正确初始化ROS的环境,导致命令无法找到。这时候需要运行source /opt/ros/<distro>/setup.bash或者在.bashrc中添加这一行。否则即使安装了相关包,系统也无法找到命令。 总结下来,解决步骤可能是:首先安装python-roslaunch,然后检查ROS安装完整性,确保环境变量正确配置。如果问题依旧,可能需要重新安装ROS或者检查安装步骤是否正确。</think>### 如何解决Ubuntu系统中“roscore命令未找到”的问题? #### 步骤1:安装 `python-roslaunch` 根据引用内容,直接运行以下命令安装 `python-roslaunch`: ```bash sudo apt install python-roslaunch ``` 此包包含ROS的核心工具(如`roscore`),适用于ROS Melodic(Ubuntu 18.04)或更早版本[^1][^2][^3]。 --- #### 步骤2:检查ROS环境配置 安装完成后,需确保ROS环境变量已正确加载: 1. 手动加载环境变量: ```bash source /opt/ros/<distro>/setup.bash ``` (将`<distro>`替换为ROS版本,如`melodic`或`noetic`) 2. **永久生效**:将以下命令添加到 `~/.bashrc` 文件末尾: ```bash echo "source /opt/ros/melodic/setup.bash" >> ~/.bashrc source ~/.bashrc ``` --- #### 步骤3:验证ROS安装完整性 如果问题仍未解决,可能是ROS未完整安装。建议重新安装ROS桌面完整版: ```bash sudo apt install ros-<distro>-desktop-full ``` 例如,ROS Melodic用户需运行: ```bash sudo apt install ros-melodic-desktop-full ``` --- #### 步骤4:检查依赖关系 修复可能的依赖问题: ```bash sudo rosdep init rosdep update ``` --- #### 补充说明 - 若使用ROS Noetic(Ubuntu 20.04+),`python-roslaunch` 已替换为 `python3-roslaunch`,需调整安装命令[^4]。 - 若环境变量未正确配置,即使安装包后系统仍可能无法识别命令(如引用5中提到的`ROS_PACKAGE_PATH`设置)[^5]。
评论 41
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值