在 Ubuntu 上创建 AppImage 应用,本质上是把可执行程序 + 依赖库 + 元数据打包成一个自包含的可执行文件。下面我从最常见、最实用的方式一步一步讲清楚。
AppImage 的核心思想:
一个 AppImage = 程序 + 运行环境 + 一个 AppDir 目录结构
运行时:
sudo apt update
sudo apt install -y \
build-essential \
wget \
fuse \
libfuse2
⚠️ Ubuntu 22.04+ 默认没有
libfuse2,AppImage 运行需要它。
appimagetool(推荐)wget https://github.com/AppImage/AppImageKit/releases/download/continuous/appimagetool-x86_64.AppImage
chmod +x appimagetool-x86_64.AppImage
sudo mv appimagetool-x86_64.AppImage /usr/local/bin/appimagetool
假设你有一个可执行程序:
myapp
AppImage 必须使用标准目录结构:
MyApp.AppDir/
├── AppRun
├── myapp.desktop
├── myapp.png
└── usr/
└── bin/
└── myapp
mkdir -p MyApp.AppDir/usr/bin
cp myapp MyApp.AppDir/usr/bin/
chmod +x MyApp.AppDir/usr/bin/myapp
AppRun 是 AppImage 的入口文件。
nano MyApp.AppDir/AppRun
内容示例:
#!/bin/bash
HERE="$(dirname "$(readlink -f "${0}")")"
exec "$HERE/usr/bin/myapp" "$@"
然后:
chmod +x MyApp.AppDir/AppRun
.desktop 文件nano MyApp.AppDir/myapp.desktop
示例:
[Desktop Entry]
Name=MyApp
Exec=myapp
Icon=myapp
Type=Application
Categories=Utility;
cp myapp.png MyApp.AppDir/
appimagetool MyApp.AppDir
成功后你会看到类似:
MyApp-x86_64.AppImage
✅ 这就是你的 AppImage 应用
chmod +x MyApp-x86_64.AppImage
./MyApp-x86_64.AppImage
如果你的程序依赖动态库(如 Qt、GTK、OpenCV):
linuxdeploywget https://github.com/linuxdeploy/linuxdeploy/releases/download/continuous/linuxdeploy-x86_64.AppImage
chmod +x linuxdeploy-x86_64.AppImage
使用:
./linuxdeploy-x86_64.AppImage \
--appdir MyApp.AppDir \
--executable myapp \
--desktop-file myapp.desktop \
--icon-file myapp.png \
--output appimage
它会:
.so 依赖AppRun✅ 这是生产环境推荐方式
sudo apt install libfuse2
linuxdeployldd myapp 检查依赖✅ 适合:
❌ 不适合:
程序 → AppDir → appimagetool → .AppImage
如果你愿意,可以告诉我:
我可以给你针对你项目的 AppImage 模板。