Skip to content

Instantly share code, notes, and snippets.

@msanjeevkumar
Created August 15, 2024 01:51
Show Gist options
  • Save msanjeevkumar/edbfebbae976ab7b2cb2e4f22cb6b374 to your computer and use it in GitHub Desktop.
Save msanjeevkumar/edbfebbae976ab7b2cb2e4f22cb6b374 to your computer and use it in GitHub Desktop.
#!/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://downloader.cursor.sh/linux/appImage/x64"
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."
@msanjeevkumar
Copy link
Author

msanjeevkumar commented Aug 15, 2024

Automated setup and update script for Cursor IDE on Ubuntu/Debian-based Linux systems. This script downloads the latest Cursor AppImage, sets up desktop integration, and creates a convenient launcher. It handles icon setup, desktop entry creation, and launcher script

Features:

  • Downloads and installs the latest Cursor AppImage
  • Sets up desktop integration (icon and .desktop file)
  • Creates a launcher script with argument support
  • Updates desktop database and icon cache

Quick Install (Please review the script before running):

curl -sSL "https://gist.githubusercontent.com/msanjeevkumar/edbfebbae976ab7b2cb2e4f22cb6b374/raw/005490f3c968b68645bb649612cb5303fdd4a48e/cursor_setup_and_update.sh" | bash

Usage:

  1. Save this script as 'cursor_setup_and_update.sh'
  2. Make it executable: chmod +x cursor_setup_and_update.sh
  3. Run it: ./cursor_setup_and_update.sh

After installation, launch Cursor with: cursor [file_or_directory]

Note: This script is designed for Ubuntu/Debian-based systems and may need modifications for other distributions.

@aidrecabrera
Copy link

Your script perfectly worked. Thank you for this!

@Potato-Ninja
Copy link

Turning off sandbox worked for me

~$ ~/Applications/cursor.AppImage --no-sandbox

Anyways thanks for your script.

@nurfaizfoat
Copy link

nurfaizfoat commented Aug 25, 2024

I'm in the same boat with Potato-Ninja. Sandbox needs to be turned off for Cursor to work. Here is the tweaked script based from msanjeevkumar's

Thanks a bunch for OP for the initial script!

#!/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://downloader.cursor.sh/linux/appImage/x64"
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} --no-sandbox "\$@" > ~/.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."

@Potato-Ninja
Copy link

Potato-Ninja commented Sep 1, 2024

Also, I suggest updating the App Icon with this one: https://www.cursor.com/assets/images/logo.svg
As the other one is Ugly AF.

Here is the updated script.

#!/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://downloader.cursor.sh/linux/appImage/x64"
ICON_DOWNLOAD_URL="https://www.cursor.com/assets/images/logo.svg"
APPIMAGE_NAME="cursor.AppImage"
APPIMAGE_PATH="${APP_DIR}/${APPIMAGE_NAME}"
ICON_PATH="${ICON_DIR}/cursor-icon.svg"
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} --no-sandbox "\$@" > ~/.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."

@famonfa
Copy link

famonfa commented Sep 5, 2024

Fantastic! Thank you!

@Another-DevX
Copy link

Another-DevX commented Sep 9, 2024

@Potato-Ninja
The image you shared is quite pixelated. This one is much better.
ICON_DOWNLOAD_URL="https://global.discourse-cdn.com/business7/uploads/cursor1/original/2X/a/a4f78589d63edd61a2843306f8e11bad9590f0ca.png"

@Potato-Ninja
Copy link

@Another-DevX
Lol mate. It's a SVG, it can never be pixelated.

You sent the same image.

@Another-DevX
Copy link

@Potato-Ninja, IDK why it seems pixelated on my Ubuntu setup, but let me, re-check

@Easy-Cloud-in
Copy link

@Potato-Ninja Thank you it worked like a charm. Let me know if I want to update the Cursor AI, I have to run the script each time.
Can you make a script to completely remove the Cursor AI from my system?

@Potato-Ninja
Copy link

@Easy-Cloud-in

You can easily update Cursor using in app button.
Everytime there is and update you will find a button in the bottom left (Update Cursor). You can just click it and get the latest update.

@Easy-Cloud-in
Copy link

@Potato-Ninja Thank you.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment