Last active
July 2, 2025 15:32
-
-
Save ka2kama/4f967dd4ba4e8834886761619dd8705e to your computer and use it in GitHub Desktop.
Install Cursor to Ubuntu 24.04
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/bin/bash | |
| set -euo pipefail | |
| # Step 1: Declare installation paths and variables | |
| CURSOR_DIR="$HOME/Applications/cursor" | |
| APPIMAGE_DIR="$CURSOR_DIR/images" | |
| EXTRACTED_DIR="$CURSOR_DIR/squashfs-root" | |
| BIN_PATH="$EXTRACTED_DIR/usr/bin/cursor" | |
| DESKTOP_DIR="$HOME/.local/share/applications" | |
| DESKTOP_FILE_PATH="$DESKTOP_DIR/cursor.desktop" | |
| SCRIPT_PATH="$HOME/.local/bin/cursor" | |
| ICON_PATH="$HOME/.local/share/icons/cursor.png" | |
| LOG_FILE_PATH="$HOME/.local/share/cursor/cursor.log" | |
| DOWNLOAD_API_URL="https://cursor.com/api/download?platform=linux-x64&releaseTrack=stable" | |
| APPIMAGE_PREFIX="Cursor-" | |
| APPIMAGE_SUFFIX="-x86_64.AppImage" | |
| MAX_KEEP_INSTALLED_VERSIONS=3 | |
| # Step 2: Create required directories | |
| mkdir -p "$APPIMAGE_DIR" \ | |
| "$DESKTOP_DIR" \ | |
| "$(dirname "$SCRIPT_PATH")" \ | |
| "$(dirname "$ICON_PATH")" \ | |
| "$(dirname "$LOG_FILE_PATH")" | |
| cd "$CURSOR_DIR" | |
| # Step 3: Download latest version if not already installed | |
| # 3.1: Check current installation | |
| CURRENT_APPIMAGE_PATH=$(find "$APPIMAGE_DIR" -name "$APPIMAGE_PREFIX*$APPIMAGE_SUFFIX" -printf '%f\n' \ | |
| | sort -Vr \ | |
| | head -n 1) | |
| CURRENT_APPIMAGE_PATH=$(find "$APPIMAGE_DIR" -name "$APPIMAGE_PREFIX*$APPIMAGE_SUFFIX" -printf '%f\n' \ | |
| | sort -Vr \ | |
| | head -n 1) | |
| CURRENT_VERSION=$(basename "$CURRENT_APPIMAGE_PATH" | sed "s/^$APPIMAGE_PREFIX//; s/$APPIMAGE_SUFFIX$//") | |
| # 3.2: Fetch latest version information | |
| DOWNLOAD_URL=$(curl -sL "$DOWNLOAD_API_URL" | jq -r '.downloadUrl') | |
| LATEST_APPIMAGE=$(basename "$DOWNLOAD_URL") | |
| LATEST_VERSION=$(echo "$LATEST_APPIMAGE" | sed "s/^$APPIMAGE_PREFIX//; s/$APPIMAGE_SUFFIX$//") | |
| echo "Current: $CURRENT_VERSION" | |
| echo "Latest : $LATEST_VERSION" | |
| # 3.3: Download new version if not installed | |
| if [ "$CURRENT_VERSION" != "$LATEST_VERSION" ]; then | |
| echo "Downloading $LATEST_APPIMAGE..." | |
| trap "rm -f ""$APPIMAGE_DIR"/"$LATEST_APPIMAGE""; echo -e '\nDownload cancelled. Cleaning up...'; exit 1" SIGINT | |
| curl -LOJ --remove-on-error "$DOWNLOAD_URL" --output-dir "$APPIMAGE_DIR" | |
| # Remove old AppImages, keeping only a constant number of versions | |
| find "$APPIMAGE_DIR" -name "$APPIMAGE_PREFIX*$APPIMAGE_SUFFIX" \ | |
| | sort -Vr \ | |
| | tail -n +$((MAX_KEEP_INSTALLED_VERSIONS + 1)) \ | |
| | xargs rm -f | |
| else | |
| echo "Already downloaded the latest version ($LATEST_VERSION)" | |
| exit 0 | |
| fi | |
| chmod +x "$APPIMAGE_DIR/$LATEST_APPIMAGE" | |
| # Step 4: Extract application binary | |
| rm -rf "$EXTRACTED_DIR" | |
| "$APPIMAGE_DIR/$LATEST_APPIMAGE" --appimage-extract | |
| chmod +x "$BIN_PATH" | |
| # Step 5: Configure application launcher | |
| cat <<EOF > "$SCRIPT_PATH" | |
| #!/bin/bash | |
| # Show version number when --version or -v flag is used | |
| if [ "\$1" = "--version" ] || [ "\$1" = "-v" ]; then | |
| echo "Cursor version: $LATEST_VERSION" | |
| exit 0 | |
| fi | |
| "$BIN_PATH" --no-sandbox "\$@" 2>&1 \ | |
| | grep -v '@todesktop/runtime: skipping autoUpdater initialization because application is not in AppImage.' \ | |
| >> "$LOG_FILE_PATH" | |
| EOF | |
| chmod +x "$SCRIPT_PATH" | |
| # Step 6: Install application icon | |
| cp "$EXTRACTED_DIR/code.png" "$ICON_PATH" | |
| # Step 7: Create desktop integration | |
| if [ ! -f "$DESKTOP_FILE_PATH" ] \ | |
| || [ "$(grep -oP '(?<=^Exec=).*' "$DESKTOP_FILE_PATH")" != "$SCRIPT_PATH" ] \ | |
| || [ "$(grep -oP '(?<=^Icon=).*' "$DESKTOP_FILE_PATH")" != "$ICON_PATH" ]; then | |
| cat <<EOF > "$DESKTOP_FILE_PATH" | |
| [Desktop Entry] | |
| Name=Cursor | |
| Exec=$SCRIPT_PATH | |
| Terminal=false | |
| Type=Application | |
| Icon=$ICON_PATH | |
| StartupWMClass=Cursor | |
| Comment=AI-powered code editor | |
| MimeType=x-scheme-handler/cursor; | |
| Categories=Utility;Development | |
| EOF | |
| chmod +x "$DESKTOP_FILE_PATH" | |
| echo "Desktop shortcut created successfully" | |
| fi | |
| # Step 8: Update system's desktop database | |
| update-desktop-database "$DESKTOP_DIR" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment