下載安裝
地址: Releases · linuxdeploy/linuxdeploy
mv linuxdeploy-x86_64.AppImage linuxdeployqtchmod 777 linuxdeployqtsudo mv linuxdeployqt /usr/local/bin/linuxdeployqt --version
報錯
Applmage默認依賴FUSE,需要掛載自身為虛擬文件系統才能運行, ubuntu24.04沒有預裝,手動安裝
sudo apt update -y
sudo apt install libfuse2
輸出版本信息安裝成功
準備qt可執行文件
新建package文件夾準備打包, 將可執行文件復制進來,筆者這里就直接在build目錄同級創建了
mkdir package && cd packagecp ../build/simulation_client .ldd simulation_client
筆者打包是要用到兩個工具,就直接手動下載了
runtime-x86_64和appimagetool
Releases · AppImage/AppImageKit
Releases · AppImage/AppImageKit
打包腳本
#!/bin/bash
set -eAPP_NAME="simulation_client"
EXECUTABLE="./$APP_NAME"
ICON_FILE="./simulation.png"
ICON_NAME="simulation"
DESKTOP_FILE="$APP_NAME.desktop"
APPDIR="$APP_NAME.AppDir"
RUNTIME_FILE="./runtime-x86_64"
APPIMAGETOOL="./appimagetool"# 檢查可執行文件是否存在
if [ ! -f "$EXECUTABLE" ]; thenecho "錯誤:可執行文件 $EXECUTABLE 不存在"exit 1
fi# 檢查圖標文件是否存在
if [ ! -f "$ICON_FILE" ]; thenecho "錯誤:圖標文件 $ICON_FILE 不存在"exit 1
fi# 檢查 appimagetool 是否存在
if [ ! -f "$APPIMAGETOOL" ]; thenecho "錯誤:appimagetool 不存在,請手動下載并放在當前目錄"echo "下載地址:https://github.com/AppImage/AppImageKit/releases/download/continuous/appimagetool-x86_64.AppImage"exit 1
fi# 檢查 runtime 是否存在
if [ ! -f "$RUNTIME_FILE" ]; thenecho "錯誤:runtime-x86_64 不存在,請手動下載并放在當前目錄"echo "下載地址:https://github.com/AppImage/type2-runtime/releases/download/continuous/runtime-x86_64"exit 1
fi# 設置可執行權限
chmod +x "$EXECUTABLE"
chmod +x "$APPIMAGETOOL"# 生成桌面文件
cat > "$DESKTOP_FILE" << EOF
[Desktop Entry]
Type=Application
Name=Simulation Client
Exec=$APP_NAME
Icon=$ICON_NAME
Categories=Utility;
Terminal=false
Comment=Simulation Client Application
EOFecho "桌面文件已生成: $DESKTOP_FILE"# 清理舊的 AppDir
rm -rf "$APPDIR"# 使用 linuxdeployqt 部署依賴、桌面文件和圖標
linuxdeployqt \--appdir="$APPDIR" \-e "$EXECUTABLE" \-d "$DESKTOP_FILE" \-i "$ICON_FILE"# 復制圖標到多個標準尺寸目錄
SIZES=("16x16" "32x32" "64x64" "128x128" "256x256")
for size in "${SIZES[@]}"; domkdir -p "$APPDIR/usr/share/icons/hicolor/$size/apps"cp "$ICON_FILE" "$APPDIR/usr/share/icons/hicolor/$size/apps/${ICON_NAME}.png"
done
echo "圖標已復制到多個標準尺寸目錄"# 生成 AppImage,指定輸出文件名
echo "正在使用本地工具生成 AppImage..."
"$APPIMAGETOOL" \--runtime-file "$RUNTIME_FILE" \"$APPDIR" \"simulation_client.AppImage"# 自動清理中間文件
echo "正在清理中間文件..."
rm -rf "$APPDIR"
rm -f "$DESKTOP_FILE"echo "清理完成..."ls -l simulation_client.AppImage
常用的Categories分類:
Utility; - 實用工具
Development; - 開發工具
System; - 系統工具
Network; - 網絡應用
Graphics; - 圖形應用
Office; - 辦公軟件