Ubuntu上Cursor的安装与配置

Cursor 目前仅为 Linux 提供了 AppImage 格式的应用程序文件。然而,直接下载并运行 AppImage 文件可能会遇到以下问题:

  • 权限问题或者沙箱问题:需要安装FUSE或者使用--no-sandbox之类的启动选项运行
  • 无法通过应用启动器启动:无法直接点击图标启动应用程序。

我经过搜索和实验,按照下面的步骤应该可以顺利在Ubuntu上运行Cursor。

基本步骤

  1. 将下面的脚本保存为cursor_setup_and_update.sh,需注意的是其中的DOWNLOAD_URL要更新为最新的下载地址。

cursor_setup_and_update.sh

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
#!/bin/bash

set -euo pipefail

# Directory setup
APP_DIR="${HOME}/Applications"
ICON_DIR="${HOME}/.local/share/icons"
DESKTOP_DIR="${HOME}/.local/share/applications"
BIN_DIR="${HOME}/.local/bin"

# File paths
DOWNLOAD_URL="https://downloads.cursor.com/production/0781e811de386a0c5bcb07ceb259df8ff8246a52/linux/x64/Cursor-0.49.6-x86_64.AppImage"
ICON_DOWNLOAD_URL="https://www.cursor.com/brand/icon.svg"
APPIMAGE_NAME="cursor.AppImage"
APPIMAGE_PATH="${APP_DIR}/${APPIMAGE_NAME}"
ICON_PATH="${ICON_DIR}/cursor-icon.png"
DESKTOP_FILE_PATH="${DESKTOP_DIR}/cursor.desktop"
LAUNCHER_SCRIPT="${BIN_DIR}/cursor"

# Utility functions
log() { printf '%s\n' "$*"; }
error() { printf 'Error: %s\n' "$*" >&2; exit 1; }

# Create necessary directories
mkdir -p "${APP_DIR}" "${ICON_DIR}" "${DESKTOP_DIR}" "${BIN_DIR}"

# Download the latest Cursor AppImage
log "Downloading the latest Cursor AppImage..."
curl -L "${DOWNLOAD_URL}" -o "${APPIMAGE_PATH}" || error "Failed to download Cursor AppImage"
chmod +x "${APPIMAGE_PATH}"
log "Downloaded and made executable: ${APPIMAGE_PATH}"

# Download the Cursor icon if it doesn't exist
if [ ! -f "${ICON_PATH}" ]; then
curl -sSo "${ICON_PATH}" "${ICON_DOWNLOAD_URL}" || error "Failed to download icon"
log "Downloaded logo to: ${ICON_PATH}"
fi

# Create or update the .desktop file
cat > "${DESKTOP_FILE_PATH}" << EOF
[Desktop Entry]
Name=Cursor
Exec=${LAUNCHER_SCRIPT} %F
Terminal=false
Type=Application
Icon=${ICON_PATH}
StartupWMClass=Cursor
X-AppImage-Version=latest
Comment=Cursor is an AI-first coding environment.
MimeType=x-scheme-handler/cursor;
Categories=Utility;Development
EOF
chmod +x "${DESKTOP_FILE_PATH}"
log "Updated .desktop file at: ${DESKTOP_FILE_PATH}"

# Create the launcher script
cat > "${LAUNCHER_SCRIPT}" << EOF
#!/bin/bash
nohup ${APPIMAGE_PATH} "\$@" > ~/.cursor_log 2>&1 &
EOF
chmod +x "${LAUNCHER_SCRIPT}"
log "Created launcher script: ${LAUNCHER_SCRIPT}"

# Update the desktop database
update-desktop-database "${DESKTOP_DIR}" || log "Failed to update desktop database. You may need to restart your session."

# Update icon cache
gtk-update-icon-cache -f -t ~/.local/share/icons || log "Failed to update icon cache. You may need to restart your session."

log "Cursor has been successfully installed and updated."
log "To run Cursor, you can now:"
log "1. Look for 'Cursor' in your application launcher"
log "2. Run it from the terminal with: cursor"
log "3. Run it directly with: ${APPIMAGE_PATH}"
log "You can also open files or directories with Cursor by using: cursor <file_or_directory>"
log "You may need to log out and log back in for all changes to take effect."
log "If you encounter any issues, check the ~/.cursor_log file for error messages."
  1. 打开终端,运行chmod +x cursor_setup_and_update.sh
  2. 运行./cursor_setup_and_update.sh
  3. 为避免 AppImage 的沙箱问题,需要为 Cursor 创建一个 AppArmor 配置文件。编辑/etc/apparmor.d/cursor/cursor-appimage
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    # This profile allows everything and only exists to give the
    # application a name instead of having the label "unconfined"

    abi <abi/4.0>,
    include <tunables/global>

    profile cursor /home/{username}/Applications/cursor*.AppImage flags=(unconfined) {
    userns,

    # Site-specific additions and overrides. See local/README for details.
    include if exists <local/cursor>
    }
    注意:要将/home/{username}替换为实际的用户目录路径
  4. 加载配置文件:sudo apparmor_parser -r /etc/apparmor.d/cursor-appimage

完成以上步骤后,Cursor 应该可以正常运行,且可以通过应用启动器、命令行或直接双击启动。如果仍然遇到问题,可以检查日志文件 ~/.cursor_log 看看具体的错误信息。 最后不得不吐槽一下,都这么多年了,Ubuntu还是一个使用者众多的发行版本,然而安装一个应用程序却还是有不少坑,需要专门来写笔记免得忘记了,实在是拉垮。

参考资料