制作并安装Deb包后执行命令提示‘command not found’的问题求助
解决Debian包中testhello命令找不到的问题
出现testhello: command not found的核心原因是:你在bash里输入的命令是testhello,但实际安装的文件是testhello.py,系统无法自动匹配;另外脚本缺少必要的执行配置,以下是具体解决步骤:
步骤1:修改脚本名称与添加执行头
- 进入打包目录的bin文件夹:
cd /testhello/usr/bin - 将
testhello.py重命名为testhello:mv testhello.py testhello - 编辑
testhello文件,在第一行添加shebang头(告诉系统用Python3执行):#!/usr/bin/env python3 print("hello world")
步骤2:设置脚本可执行权限
给脚本添加执行权限,否则系统无法直接运行:
chmod +x /testhello/usr/bin/testhello
步骤3:重新打包并安装
- 回到打包根目录:
cd / - 重新生成deb包:
dpkg -b testhello - 重新安装包:
sudo dpkg -i testhello.deb
可选:保留原文件名的替代方案
如果不想修改testhello.py的文件名,需要额外做两步:
- 给
testhello.py添加shebang头并设置可执行权限(同步骤1、2) - 在打包目录的
/testhello/usr/bin下创建软链接:
安装后,ln -s testhello.py testhello/usr/bin/testhello会指向testhello.py,输入testhello即可执行。
另外注意:你提到在/bin目录看到testhello.py,这不符合Debian打包规范,标准用户二进制文件应放在/usr/bin,打包时的testhello/usr/bin路径会被映射到系统的/usr/bin,请确认打包路径是否正确。
内容的提问来源于stack exchange,提问作者falsekein
相关产品推荐
相关产品推荐

