cursor icon indicating copy to clipboard operation
cursor copied to clipboard

Bug: Cursor is not launching through `cusrsor .` or `code .` command in WSL2 Distro ubuntu.

Open startup-dreamer opened this issue 2 years ago • 26 comments
trafficstars

I am trying to launch cursor through WSL ubuntu but there is some error related to .cursor-server file screenshots: image image image image

startup-dreamer avatar Sep 04 '23 20:09 startup-dreamer

Have the same issue on my end.

Umar-Azam avatar Sep 08 '23 02:09 Umar-Azam

Yep, this is expected atm. We will look into fixing as soon as we can.

truell20 avatar Sep 08 '23 22:09 truell20

@truell20 please close this issue as soon as it is fixed so that I will be able to use cursor again with WSL

startup-dreamer avatar Sep 16 '23 02:09 startup-dreamer

Just to add to this issue, I see a different sort of error when attempting to run cursor in Ubuntu on WSL2:

ursor
To use Cursor with the Windows Subsystem for Linux, please install Cursor in Windows and uninstall the Linux version in WSL. You can then use the `cursor` command in a WSL terminal just as you would in a normal command prompt.
Do you want to continue anyway? [y/N] y
To no longer see this prompt, start Cursor with the environment variable DONT_PROMPT_WSL_INSTALL defined.
/mnt/c/Users/taoha/AppData/Local/Programs/cursor/resources/app/bin/cursor: 62: /mnt/c/Users/taoha/AppData/Local/Programs/cursor/resources/app/bin/../cursor: not found

worldofgeese avatar Oct 03 '23 11:10 worldofgeese

Just to add to this issue, I see a different sort of error when attempting to run cursor in Ubuntu on WSL2:

ursor
To use Cursor with the Windows Subsystem for Linux, please install Cursor in Windows and uninstall the Linux version in WSL. You can then use the `cursor` command in a WSL terminal just as you would in a normal command prompt.
Do you want to continue anyway? [y/N] y
To no longer see this prompt, start Cursor with the environment variable DONT_PROMPT_WSL_INSTALL defined.
/mnt/c/Users/taoha/AppData/Local/Programs/cursor/resources/app/bin/cursor: 62: /mnt/c/Users/taoha/AppData/Local/Programs/cursor/resources/app/bin/../cursor: not found

Same thing here! Also noticed it broke my code . command as well ... luckily I can just open Cursor and go on my way, watching this for updates 🫡

Jacksonmills avatar Oct 19 '23 12:10 Jacksonmills

Any updates on this? Still broken for me

Jacksonmills avatar Nov 09 '23 03:11 Jacksonmills

It's unbelievable this is still broken after so many months, and the fix is rather simple. Sadly Cursor is not open source... but here's a quick workaround based on VS Code's current launcher from WSL:

[!CAUTION] This will most likely break after Cursor gets an update. Hopefully they'll fix this in the next update, but if not these tweaks may need to be done again after every update.

[!NOTE] You should install the WSL Extension before attempting these steps

[!IMPORTANT] I opened a WSL folder at least once before doing these steps. Doing so installed Cursor's WSL Server in ~/.cursor-server/bin. I'm not sure if this altered VS Code script would trigger that too if you directly run cursor without the WSL Server installed.

  1. Open the cursor linux script
    • Most likely located at C:\Users\<your user>\AppData\Local\Programs\cursor\resources\app\bin\
    • If you've installed the cursor command you can also:
      • Use which in WSL:
        $ which cursor
        /mnt/c/Users/lesmo/AppData/Local/Programs/cursor/resources/app/bin/cursor
        
      • Use where in Windows' Command Prompt:
        > where cursor
        c:\Users\lesmo\AppData\Local\Programs\cursor\resources\app\bin\cursor
        c:\Users\lesmo\AppData\Local\Programs\cursor\resources\app\bin\cursor.cmd
        
      • Use (Get-Command cursor).Source in PowerShell :
        > (Get-Command code).Source
        C:\Users\lesmo\AppData\Local\Programs\Microsoft VS Code\bin\code.cmd
        
  2. Copy the code linux script contents into the cursor one
    • Most likely located at C:\Users\<your user>\AppData\Local\Programs\Microsoft VS Code\bin\
  3. Patch the script with:
    • Cursor values for the variables:
      • COMMIT should have the value of the binary under ~/.cursor-server/bin, which for me right now is 56becd74fc3058ee97a0b2496d8ae7ad2c2fcb10
      • APP_NAME should be "cursor"
      • NAME should be "Cursor"
      • SERVERDATAFOLDER should be ".cursor-server"
      • VSCODE_PATH should be "$(dirname "$(dirname "$(dirname "$(dirname "$(realpath "$0")")")")")"
        • Paths slightly differ from VS Code, so this extra dirname calls are necessary)
    • Fix the semi-invalid output from the call to Cursor as CLI in line 47
      • The cat /tmp/remote-wsl-loc.txt expects to only output a path, but it outputs 2 lines that breaks the script. To fix this, we forcibly get only the 2nd line:
        WSL_EXT_WLOC=$(cat /tmp/remote-wsl-loc.txt | head -2 | tail -1)
        

Cursor will now be correctly launched by whatever WSL instance invokes it:

https://github.com/getcursor/cursor/assets/2228196/f3f200c8-9325-4b49-979d-49302985e58e

This is my current cursor file contents:

#!/usr/bin/env sh
#
# Copyright (c) Microsoft Corporation. All rights reserved.
# Licensed under the MIT License. See License.txt in the project root for license information.
if [ "$VSCODE_WSL_DEBUG_INFO" = true ]; then
	set -x
fi

COMMIT="56becd74fc3058ee97a0b2496d8ae7ad2c2fcb10"
APP_NAME="cursor"
QUALITY="stable"
NAME="Cursor"
SERVERDATAFOLDER=".cursor-server"
VSCODE_PATH="$(dirname "$(dirname "$(dirname "$(dirname "$(realpath "$0")")")")")"
ELECTRON="$VSCODE_PATH/$NAME.exe"

IN_WSL=false
if [ -n "$WSL_DISTRO_NAME" ]; then
	# $WSL_DISTRO_NAME is available since WSL builds 18362, also for WSL2
	IN_WSL=true
else
	WSL_BUILD=$(uname -r | sed -E 's/^[0-9.]+-([0-9]+)-Microsoft.*|.*/\1/')
	if [ -n "$WSL_BUILD" ]; then
		if [ "$WSL_BUILD" -ge 17063 ]; then
			# WSLPATH is available since WSL build 17046
			# WSLENV is available since WSL build 17063
			IN_WSL=true
		else
			# If running under older WSL, don't pass cli.js to Electron as
			# environment vars cannot be transferred from WSL to Windows
			# See: https://github.com/microsoft/BashOnWindows/issues/1363
			#      https://github.com/microsoft/BashOnWindows/issues/1494
			"$ELECTRON" "$@"
			exit $?
		fi
	fi
fi
if [ $IN_WSL = true ]; then

	export WSLENV="ELECTRON_RUN_AS_NODE/w:$WSLENV"
	CLI=$(wslpath -m "$VSCODE_PATH/resources/app/out/cli.js")

	# use the Remote WSL extension if installed
	WSL_EXT_ID="ms-vscode-remote.remote-wsl"

	ELECTRON_RUN_AS_NODE=1 "$ELECTRON" "$CLI" --locate-extension $WSL_EXT_ID >/tmp/remote-wsl-loc.txt 2>/dev/null </dev/null
	WSL_EXT_WLOC=$(cat /tmp/remote-wsl-loc.txt | head -2 | tail -1)

	if [ -n "$WSL_EXT_WLOC" ]; then
		# replace \r\n with \n in WSL_EXT_WLOC
		WSL_CODE=$(wslpath -u "${WSL_EXT_WLOC%%[[:cntrl:]]}")/scripts/wslCode.sh
		"$WSL_CODE" "$COMMIT" "$QUALITY" "$ELECTRON" "$APP_NAME" "$SERVERDATAFOLDER" "$@"
		exit $?
	fi

elif [ -x "$(command -v cygpath)" ]; then
	CLI=$(cygpath -m "$VSCODE_PATH/resources/app/out/cli.js")
else
	CLI="$VSCODE_PATH/resources/app/out/cli.js"
fi
ELECTRON_RUN_AS_NODE=1 "$ELECTRON" "$CLI" "$@"
exit $?

P.S.: Cursor ppl, hire me? lol

lesmo avatar Feb 19 '24 07:02 lesmo

Also see issue #807

vincentsch avatar Feb 20 '24 09:02 vincentsch

Connecting to update.code.visualstudio.com (update.code.visualstudio.com)|13.107.213.40|:443... connected. HTTP request sent, awaiting response... 404 Not Found 2024-03-14 15:13:18 ERROR 404: Not Found.

ERROR: Failed to download https://update.code.visualstudio.com/commit:56becd74fc3058ee97a0b2496d8ae7ad2c2fcb10-1710443218/server-linux-x64/stable to /root/.cursor-server/bin/56becd74fc3058ee97a0b2496d8ae7ad2c2fcb10-1710443218-1710443598.tar.gz

i get this error

It's unbelievable this is still broken after so many months, and the fix is rather simple. Sadly Cursor is not open source... but here's a quick workaround based on VS Code's current launcher from WSL:

Caution

This will most likely break after Cursor gets an update. Hopefully they'll fix this in the next update, but if not these tweaks may need to be done again after every update.

Note

You should install the WSL Extension before attempting these steps

Important

I opened a WSL folder at least once before doing these steps. Doing so installed Cursor's WSL Server in ~/.cursor-server/bin. I'm not sure if this altered VS Code script would trigger that too if you directly run cursor without the WSL Server installed.

  1. Open the cursor linux script

    • Most likely located at C:\Users\<your user>\AppData\Local\Programs\cursor\resources\app\bin\

    • If you've installed the cursor command you can also:

      • Use which in WSL:
        $ which cursor
        /mnt/c/Users/lesmo/AppData/Local/Programs/cursor/resources/app/bin/cursor
        
      • Use where in Windows' Command Prompt:
        > where cursor
        c:\Users\lesmo\AppData\Local\Programs\cursor\resources\app\bin\cursor
        c:\Users\lesmo\AppData\Local\Programs\cursor\resources\app\bin\cursor.cmd
        
      • Use (Get-Command cursor).Source in PowerShell :
        > (Get-Command code).Source
        C:\Users\lesmo\AppData\Local\Programs\Microsoft VS Code\bin\code.cmd
        
  2. Copy the code linux script contents into the cursor one

    • Most likely located at C:\Users\<your user>\AppData\Local\Programs\Microsoft VS Code\bin\
  3. Patch the script with:

    • Cursor values for the variables:

      • COMMIT should have the value of the binary under ~/.cursor-server/bin, which for me right now is 56becd74fc3058ee97a0b2496d8ae7ad2c2fcb10

      • APP_NAME should be "cursor"

      • NAME should be "Cursor"

      • SERVERDATAFOLDER should be ".cursor-server"

      • VSCODE_PATH should be "$(dirname "$(dirname "$(dirname "$(dirname "$(realpath "$0")")")")")"

        • Paths slightly differ from VS Code, so this extra dirname calls are necessary)
    • Fix the semi-invalid output from the call to Cursor as CLI in line 47

      • The cat /tmp/remote-wsl-loc.txt expects to only output a path, but it outputs 2 lines that breaks the script. To fix this, we forcibly get only the 2nd line:
        WSL_EXT_WLOC=$(cat /tmp/remote-wsl-loc.txt | head -2 | tail -1)
        

Cursor will now be correctly launched by whatever WSL instance invokes it:

20240219_014531.mp4 This is my current cursor file contents:

#!/usr/bin/env sh
#
# Copyright (c) Microsoft Corporation. All rights reserved.
# Licensed under the MIT License. See License.txt in the project root for license information.
if [ "$VSCODE_WSL_DEBUG_INFO" = true ]; then
	set -x
fi

COMMIT="56becd74fc3058ee97a0b2496d8ae7ad2c2fcb10"
APP_NAME="cursor"
QUALITY="stable"
NAME="Cursor"
SERVERDATAFOLDER=".cursor-server"
VSCODE_PATH="$(dirname "$(dirname "$(dirname "$(dirname "$(realpath "$0")")")")")"
ELECTRON="$VSCODE_PATH/$NAME.exe"

IN_WSL=false
if [ -n "$WSL_DISTRO_NAME" ]; then
	# $WSL_DISTRO_NAME is available since WSL builds 18362, also for WSL2
	IN_WSL=true
else
	WSL_BUILD=$(uname -r | sed -E 's/^[0-9.]+-([0-9]+)-Microsoft.*|.*/\1/')
	if [ -n "$WSL_BUILD" ]; then
		if [ "$WSL_BUILD" -ge 17063 ]; then
			# WSLPATH is available since WSL build 17046
			# WSLENV is available since WSL build 17063
			IN_WSL=true
		else
			# If running under older WSL, don't pass cli.js to Electron as
			# environment vars cannot be transferred from WSL to Windows
			# See: https://github.com/microsoft/BashOnWindows/issues/1363
			#      https://github.com/microsoft/BashOnWindows/issues/1494
			"$ELECTRON" "$@"
			exit $?
		fi
	fi
fi
if [ $IN_WSL = true ]; then

	export WSLENV="ELECTRON_RUN_AS_NODE/w:$WSLENV"
	CLI=$(wslpath -m "$VSCODE_PATH/resources/app/out/cli.js")

	# use the Remote WSL extension if installed
	WSL_EXT_ID="ms-vscode-remote.remote-wsl"

	ELECTRON_RUN_AS_NODE=1 "$ELECTRON" "$CLI" --locate-extension $WSL_EXT_ID >/tmp/remote-wsl-loc.txt 2>/dev/null </dev/null
	WSL_EXT_WLOC=$(cat /tmp/remote-wsl-loc.txt | head -2 | tail -1)

	if [ -n "$WSL_EXT_WLOC" ]; then
		# replace \r\n with \n in WSL_EXT_WLOC
		WSL_CODE=$(wslpath -u "${WSL_EXT_WLOC%%[[:cntrl:]]}")/scripts/wslCode.sh
		"$WSL_CODE" "$COMMIT" "$QUALITY" "$ELECTRON" "$APP_NAME" "$SERVERDATAFOLDER" "$@"
		exit $?
	fi

elif [ -x "$(command -v cygpath)" ]; then
	CLI=$(cygpath -m "$VSCODE_PATH/resources/app/out/cli.js")
else
	CLI="$VSCODE_PATH/resources/app/out/cli.js"
fi
ELECTRON_RUN_AS_NODE=1 "$ELECTRON" "$CLI" "$@"
exit $?

P.S.: Cursor ppl, hire me? lol

rdvo avatar Mar 14 '24 19:03 rdvo

https://github.com/getcursor/cursor/issues/870#issuecomment-1951864065

I've written a small shell script that does the same thing:

#!/usr/bin/env bash

CODE_WIN_PATH="$(which code)"
CURSOR_WIN_PATH="$(which cursor)"

# overwrite cursor script with the vscode one
cp "$CODE_WIN_PATH" "$CURSOR_WIN_PATH"

# replace vscode vars and paths with cursor ones
# APP_NAME should not be replaced, since .cursor-server remote-cli still gets downloaded and extracted as "code" executable
#sed -i 's|APP_NAME="code"|APP_NAME="cursor"|' $CURSOR_WIN_PATH
sed -i 's|NAME="Code"|NAME="Cursor"|' $CURSOR_WIN_PATH
sed -i 's|SERVERDATAFOLDER=".vscode-server"|SERVERDATAFOLDER=".cursor-server"|' $CURSOR_WIN_PATH
sed -i -E 's|VSCODE_PATH=".+"|VSCODE_PATH="$(dirname "$(dirname "$(dirname "$(dirname "$(realpath "$0")")")")")"|' $CURSOR_WIN_PATH

# fix output from the Cursor in CLI
sed -i -E 's|WSL_EXT_WLOC=(.+)|WSL_EXT_WLOC=$(tail -1 /tmp/remote-wsl-loc.txt)|' $CURSOR_WIN_PATH

I'm not 100% sure about the APP_NAME replacement, but it only worked flawlessly for me when I left it as code, since the remote-cli that gets downloaded is still named "code" - at least for me.

stevenobird avatar Mar 20 '24 17:03 stevenobird

It's still not fixed 🤦🏻‍♂️

seigtm avatar Apr 09 '24 09:04 seigtm

I hate to say, but uninstall Cursor is the simplest solution

Fitmavincent avatar May 14 '24 00:05 Fitmavincent

You can try this:

  1. Open cursor, and connect to wsl
  2. Then run this fixWSL.sh in the wsl
#!/usr/bin/env bash

# Function to backup a file if it exists
backup_file() {
    local file_path=$1
    if [ -e "$file_path" ]; then
        mv "$file_path" "$file_path.bak"
    fi
}

# Function to safely copy a file and create a backup if it doesn't exist
safe_copy_with_backup() {
    local src=$1
    local dest=$2
    cp "$src" "$dest"
    if [ ! -e "$dest.bak" ]; then
        cp "$dest" "$dest.bak"
    fi
}

# Function to perform the sed replacements
perform_replacements() {
    local file_path=$1
    local bin_path=$2

    sed -i 's|APP_NAME="code"|APP_NAME="cursor"|' "$file_path"
    if [ -n "$bin_path" ]; then
        local commit
        commit=$(basename "$bin_path")
        sed -i "s|COMMIT=\"[^\"]*\"|COMMIT=\"$commit\"|" "$file_path"
    fi
    sed -i 's|NAME="Code"|NAME="Cursor"|' "$file_path"
    sed -i 's|SERVERDATAFOLDER=".vscode-server"|SERVERDATAFOLDER=".cursor-server"|' "$file_path"
    sed -i -E 's|VSCODE_PATH=".+"|VSCODE_PATH="$(dirname "$(dirname "$(dirname "$(dirname "$(realpath "$0")")")")")"|' "$file_path"
    sed -i -E 's|WSL_EXT_WLOC=(.+)|WSL_EXT_WLOC=$(tail -1 /tmp/remote-wsl-loc.txt)|' "$file_path"
}

# Main script execution
CODE_PATH=$(which code)
if [[ "$CODE_PATH" == *"cursor"* ]]; then
    backup_file "$CODE_PATH"
fi

CODE_WIN_PATH=$(which code)
CURSOR_WIN_PATH=$(which cursor)
BIN_PATH=$(ls -d ~/.cursor-server/bin/*/ 2>/dev/null | head -n 1)

safe_copy_with_backup "$CODE_WIN_PATH" "$CURSOR_WIN_PATH"
perform_replacements "$CURSOR_WIN_PATH" "$BIN_PATH"

dihak avatar Jun 03 '24 06:06 dihak

It's unbelievable this is still broken after so many months, and the fix is rather simple. Sadly Cursor is not open source... but here's a quick workaround based on VS Code's current launcher from WSL:

Caution

This will most likely break after Cursor gets an update. Hopefully they'll fix this in the next update, but if not these tweaks may need to be done again after every update.

Note

You should install the WSL Extension before attempting these steps

Important

I opened a WSL folder at least once before doing these steps. Doing so installed Cursor's WSL Server in ~/.cursor-server/bin. I'm not sure if this altered VS Code script would trigger that too if you directly run cursor without the WSL Server installed.

  1. Open the cursor linux script

    • Most likely located at C:\Users\<your user>\AppData\Local\Programs\cursor\resources\app\bin\

    • If you've installed the cursor command you can also:

      • Use which in WSL:
        $ which cursor
        /mnt/c/Users/lesmo/AppData/Local/Programs/cursor/resources/app/bin/cursor
        
      • Use where in Windows' Command Prompt:
        > where cursor
        c:\Users\lesmo\AppData\Local\Programs\cursor\resources\app\bin\cursor
        c:\Users\lesmo\AppData\Local\Programs\cursor\resources\app\bin\cursor.cmd
        
      • Use (Get-Command cursor).Source in PowerShell :
        > (Get-Command code).Source
        C:\Users\lesmo\AppData\Local\Programs\Microsoft VS Code\bin\code.cmd
        
  2. Copy the code linux script contents into the cursor one

    • Most likely located at C:\Users\<your user>\AppData\Local\Programs\Microsoft VS Code\bin\
  3. Patch the script with:

    • Cursor values for the variables:

      • COMMIT should have the value of the binary under ~/.cursor-server/bin, which for me right now is 56becd74fc3058ee97a0b2496d8ae7ad2c2fcb10

      • APP_NAME should be "cursor"

      • NAME should be "Cursor"

      • SERVERDATAFOLDER should be ".cursor-server"

      • VSCODE_PATH should be "$(dirname "$(dirname "$(dirname "$(dirname "$(realpath "$0")")")")")"

        • Paths slightly differ from VS Code, so this extra dirname calls are necessary)
    • Fix the semi-invalid output from the call to Cursor as CLI in line 47

      • The cat /tmp/remote-wsl-loc.txt expects to only output a path, but it outputs 2 lines that breaks the script. To fix this, we forcibly get only the 2nd line:
        WSL_EXT_WLOC=$(cat /tmp/remote-wsl-loc.txt | head -2 | tail -1)
        

Cursor will now be correctly launched by whatever WSL instance invokes it:

20240219_014531.mp4 This is my current cursor file contents:

#!/usr/bin/env sh
#
# Copyright (c) Microsoft Corporation. All rights reserved.
# Licensed under the MIT License. See License.txt in the project root for license information.
if [ "$VSCODE_WSL_DEBUG_INFO" = true ]; then
	set -x
fi

COMMIT="56becd74fc3058ee97a0b2496d8ae7ad2c2fcb10"
APP_NAME="cursor"
QUALITY="stable"
NAME="Cursor"
SERVERDATAFOLDER=".cursor-server"
VSCODE_PATH="$(dirname "$(dirname "$(dirname "$(dirname "$(realpath "$0")")")")")"
ELECTRON="$VSCODE_PATH/$NAME.exe"

IN_WSL=false
if [ -n "$WSL_DISTRO_NAME" ]; then
	# $WSL_DISTRO_NAME is available since WSL builds 18362, also for WSL2
	IN_WSL=true
else
	WSL_BUILD=$(uname -r | sed -E 's/^[0-9.]+-([0-9]+)-Microsoft.*|.*/\1/')
	if [ -n "$WSL_BUILD" ]; then
		if [ "$WSL_BUILD" -ge 17063 ]; then
			# WSLPATH is available since WSL build 17046
			# WSLENV is available since WSL build 17063
			IN_WSL=true
		else
			# If running under older WSL, don't pass cli.js to Electron as
			# environment vars cannot be transferred from WSL to Windows
			# See: https://github.com/microsoft/BashOnWindows/issues/1363
			#      https://github.com/microsoft/BashOnWindows/issues/1494
			"$ELECTRON" "$@"
			exit $?
		fi
	fi
fi
if [ $IN_WSL = true ]; then

	export WSLENV="ELECTRON_RUN_AS_NODE/w:$WSLENV"
	CLI=$(wslpath -m "$VSCODE_PATH/resources/app/out/cli.js")

	# use the Remote WSL extension if installed
	WSL_EXT_ID="ms-vscode-remote.remote-wsl"

	ELECTRON_RUN_AS_NODE=1 "$ELECTRON" "$CLI" --locate-extension $WSL_EXT_ID >/tmp/remote-wsl-loc.txt 2>/dev/null </dev/null
	WSL_EXT_WLOC=$(cat /tmp/remote-wsl-loc.txt | head -2 | tail -1)

	if [ -n "$WSL_EXT_WLOC" ]; then
		# replace \r\n with \n in WSL_EXT_WLOC
		WSL_CODE=$(wslpath -u "${WSL_EXT_WLOC%%[[:cntrl:]]}")/scripts/wslCode.sh
		"$WSL_CODE" "$COMMIT" "$QUALITY" "$ELECTRON" "$APP_NAME" "$SERVERDATAFOLDER" "$@"
		exit $?
	fi

elif [ -x "$(command -v cygpath)" ]; then
	CLI=$(cygpath -m "$VSCODE_PATH/resources/app/out/cli.js")
else
	CLI="$VSCODE_PATH/resources/app/out/cli.js"
fi
ELECTRON_RUN_AS_NODE=1 "$ELECTRON" "$CLI" "$@"
exit $?

P.S.: Cursor ppl, hire me? lol

@lesmo i think it's not a solution. each time the wsl restarted, it'll do the update and removal as following

Updating VS Code Server to version 863d2581ecda6849923a2118d93a088b0745d9d6
Removing previous installation...
Installing VS Code Server for x64 (863d2581ecda6849923a2118d93a088b0745d9d6)
Downloading: 100%
Unpacking: 100%

ahmedmustafamo avatar Jun 12 '24 16:06 ahmedmustafamo

This guide outlines how to resolve installation problems with Cursor in your WSL environment, specifically on Arch Linux but applicable to Ubuntu as well.

Here's a breakdown of the steps:

  1. Clean Uninstall:

    • Uninstall Cursor through the usual method.
    • Manually remove leftover folders related to Cursor in these locations:
      • C:/Users/<your user>/AppData/Local/Programs/
      • C:/Users/<your user>/AppData/Local/
      • C:/Users/<your user>/AppData/LocalLow/
      • C:/Users/<your user>/AppData/Roaming/
    • Delete folders:
      • C:/Users/<your user>/.cursor/
      • C:/Users/<your user>/.cursor-tutor/
  2. WSL PATH Repair:

    • Open a WSL terminal and run printenv PATH USER to view your current PATH variables.

    • Copy the output to a text editor.

    • Identify and remove any entries related to Cursor (the cursor Fix WSL install command might have added duplicates).

    • Keep the edited version in the text editor.

    • Run the following command, replacing <copied repaired version> with the edited PATH string (use quotation marks if any path contains spaces):

      PATH="<copied repaired version>"
      
  3. Fresh Install & Server Cleanup:

    • In a WSL Terminal delete the folder ~/.cursor-server.
    • Reinstall Cursor, but don't click the options to add PATH variables, +code button, or +cursor button.
  4. Manual Script Setup:

    • Start Cursor and import your VS Code settings (ensure you have the WSL extension installed).
    • Reload Cursor and connect it to WSL. Make sure ~/.cursor-server/bin/<your hash> folder is created and close cursor.
    • Refer to the comment https://github.com/getcursor/cursor/issues/807#issuecomment-1728885825
    • In the script provided, replace the following:
      • COMMIT with your unique hash (you can find this in the newly created folder ~/.cursor-server/bin/<your hash>).
      • APP_NAME="code" with APP_NAME="cursor".
      • Update VSCODE_PATH with VSCODE_PATH="$(dirname "$(dirname "$(dirname "$(dirname "$(realpath "$0")")")")")" as instructed in the comments of this issue.
  5. PATH Update for Cursor Script:

    • In the text editor where you saved the edited PATH string, add this path to the end:

      :/mnt/c/Users/<your user>/AppData/Local/Programs/cursor/resources/app/bin
      
    • In your WSL terminal run the following command, replacing <new version> with the edited PATH string (use quotation marks if any path contains spaces):

      PATH="<new version>"
      

Important Note:

  • Ensure the Cursor path in your PATH variable comes after the VS Code path. This prevents conflicts with a script named "code" in the Cursor path which was added to the PATH variable.

Persistent PATH Update (Optional):

  • To avoid manually setting the PATH every time you restart your terminal, you can add the following line to your shell configuration file (e.g., ~/.zshrc for Zsh or ~/.bashrc for Bash):

    PATH="<new version>"
    

Remember: After editing your shell configuration file, you need to source it for the changes to take effect. You can do this by running:

source ~/.zshrc  # For Zsh
source ~/.bashrc  # For Bash

This process should resolve your Cursor installation issues and allow you to launch it seamlessly within your WSL environment. By making the PATH update persistent in your shell configuration, you'll avoid the need to manually set it after every restart.

KadirBalku avatar Jul 02 '24 23:07 KadirBalku

I have provided a tutorial in my repository, please check it https://github.com/angga7togk/command-cursor-editor-linux

angga7togk avatar Jul 26 '24 14:07 angga7togk

This is still an issue and this is the only reliable fix I've found

It's unbelievable this is still broken after so many months, and the fix is rather simple. Sadly Cursor is not open source... but here's a quick workaround based on VS Code's current launcher from WSL:

Caution

This will most likely break after Cursor gets an update. Hopefully they'll fix this in the next update, but if not these tweaks may need to be done again after every update.

Note

You should install the WSL Extension before attempting these steps

Important

I opened a WSL folder at least once before doing these steps. Doing so installed Cursor's WSL Server in ~/.cursor-server/bin. I'm not sure if this altered VS Code script would trigger that too if you directly run cursor without the WSL Server installed.

  1. Open the cursor linux script

    • Most likely located at C:\Users\<your user>\AppData\Local\Programs\cursor\resources\app\bin\

    • If you've installed the cursor command you can also:

      • Use which in WSL:
        $ which cursor
        /mnt/c/Users/lesmo/AppData/Local/Programs/cursor/resources/app/bin/cursor
        
      • Use where in Windows' Command Prompt:
        > where cursor
        c:\Users\lesmo\AppData\Local\Programs\cursor\resources\app\bin\cursor
        c:\Users\lesmo\AppData\Local\Programs\cursor\resources\app\bin\cursor.cmd
        
      • Use (Get-Command cursor).Source in PowerShell :
        > (Get-Command code).Source
        C:\Users\lesmo\AppData\Local\Programs\Microsoft VS Code\bin\code.cmd
        
  2. Copy the code linux script contents into the cursor one

    • Most likely located at C:\Users\<your user>\AppData\Local\Programs\Microsoft VS Code\bin\
  3. Patch the script with:

    • Cursor values for the variables:

      • COMMIT should have the value of the binary under ~/.cursor-server/bin, which for me right now is 56becd74fc3058ee97a0b2496d8ae7ad2c2fcb10

      • APP_NAME should be "cursor"

      • NAME should be "Cursor"

      • SERVERDATAFOLDER should be ".cursor-server"

      • VSCODE_PATH should be "$(dirname "$(dirname "$(dirname "$(dirname "$(realpath "$0")")")")")"

        • Paths slightly differ from VS Code, so this extra dirname calls are necessary)
    • Fix the semi-invalid output from the call to Cursor as CLI in line 47

      • The cat /tmp/remote-wsl-loc.txt expects to only output a path, but it outputs 2 lines that breaks the script. To fix this, we forcibly get only the 2nd line:
        WSL_EXT_WLOC=$(cat /tmp/remote-wsl-loc.txt | head -2 | tail -1)
        

Cursor will now be correctly launched by whatever WSL instance invokes it:

20240219_014531.mp4 This is my current cursor file contents:

#!/usr/bin/env sh
#
# Copyright (c) Microsoft Corporation. All rights reserved.
# Licensed under the MIT License. See License.txt in the project root for license information.
if [ "$VSCODE_WSL_DEBUG_INFO" = true ]; then
	set -x
fi

COMMIT="56becd74fc3058ee97a0b2496d8ae7ad2c2fcb10"
APP_NAME="cursor"
QUALITY="stable"
NAME="Cursor"
SERVERDATAFOLDER=".cursor-server"
VSCODE_PATH="$(dirname "$(dirname "$(dirname "$(dirname "$(realpath "$0")")")")")"
ELECTRON="$VSCODE_PATH/$NAME.exe"

IN_WSL=false
if [ -n "$WSL_DISTRO_NAME" ]; then
	# $WSL_DISTRO_NAME is available since WSL builds 18362, also for WSL2
	IN_WSL=true
else
	WSL_BUILD=$(uname -r | sed -E 's/^[0-9.]+-([0-9]+)-Microsoft.*|.*/\1/')
	if [ -n "$WSL_BUILD" ]; then
		if [ "$WSL_BUILD" -ge 17063 ]; then
			# WSLPATH is available since WSL build 17046
			# WSLENV is available since WSL build 17063
			IN_WSL=true
		else
			# If running under older WSL, don't pass cli.js to Electron as
			# environment vars cannot be transferred from WSL to Windows
			# See: https://github.com/microsoft/BashOnWindows/issues/1363
			#      https://github.com/microsoft/BashOnWindows/issues/1494
			"$ELECTRON" "$@"
			exit $?
		fi
	fi
fi
if [ $IN_WSL = true ]; then

	export WSLENV="ELECTRON_RUN_AS_NODE/w:$WSLENV"
	CLI=$(wslpath -m "$VSCODE_PATH/resources/app/out/cli.js")

	# use the Remote WSL extension if installed
	WSL_EXT_ID="ms-vscode-remote.remote-wsl"

	ELECTRON_RUN_AS_NODE=1 "$ELECTRON" "$CLI" --locate-extension $WSL_EXT_ID >/tmp/remote-wsl-loc.txt 2>/dev/null </dev/null
	WSL_EXT_WLOC=$(cat /tmp/remote-wsl-loc.txt | head -2 | tail -1)

	if [ -n "$WSL_EXT_WLOC" ]; then
		# replace \r\n with \n in WSL_EXT_WLOC
		WSL_CODE=$(wslpath -u "${WSL_EXT_WLOC%%[[:cntrl:]]}")/scripts/wslCode.sh
		"$WSL_CODE" "$COMMIT" "$QUALITY" "$ELECTRON" "$APP_NAME" "$SERVERDATAFOLDER" "$@"
		exit $?
	fi

elif [ -x "$(command -v cygpath)" ]; then
	CLI=$(cygpath -m "$VSCODE_PATH/resources/app/out/cli.js")
else
	CLI="$VSCODE_PATH/resources/app/out/cli.js"
fi
ELECTRON_RUN_AS_NODE=1 "$ELECTRON" "$CLI" "$@"
exit $?

P.S.: Cursor ppl, hire me? lol

SC7639 avatar Aug 14 '24 16:08 SC7639

Problem still exists

Mayurifag avatar Aug 26 '24 18:08 Mayurifag

It's unbelievable this is still broken after so many months, and the fix is rather simple. Sadly Cursor is not open source... but here's a quick workaround based on VS Code's current launcher from WSL:

Caution

This will most likely break after Cursor gets an update. Hopefully they'll fix this in the next update, but if not these tweaks may need to be done again after every update.

Note

You should install the WSL Extension before attempting these steps

Important

I opened a WSL folder at least once before doing these steps. Doing so installed Cursor's WSL Server in ~/.cursor-server/bin. I'm not sure if this altered VS Code script would trigger that too if you directly run cursor without the WSL Server installed.

  1. Open the cursor linux script

    • Most likely located at C:\Users\<your user>\AppData\Local\Programs\cursor\resources\app\bin\

    • If you've installed the cursor command you can also:

      • Use which in WSL:
        $ which cursor
        /mnt/c/Users/lesmo/AppData/Local/Programs/cursor/resources/app/bin/cursor
        
      • Use where in Windows' Command Prompt:
        > where cursor
        c:\Users\lesmo\AppData\Local\Programs\cursor\resources\app\bin\cursor
        c:\Users\lesmo\AppData\Local\Programs\cursor\resources\app\bin\cursor.cmd
        
      • Use (Get-Command cursor).Source in PowerShell :
        > (Get-Command code).Source
        C:\Users\lesmo\AppData\Local\Programs\Microsoft VS Code\bin\code.cmd
        
  2. Copy the code linux script contents into the cursor one

    • Most likely located at C:\Users\<your user>\AppData\Local\Programs\Microsoft VS Code\bin\
  3. Patch the script with:

    • Cursor values for the variables:

      • COMMIT should have the value of the binary under ~/.cursor-server/bin, which for me right now is 56becd74fc3058ee97a0b2496d8ae7ad2c2fcb10

      • APP_NAME should be "cursor"

      • NAME should be "Cursor"

      • SERVERDATAFOLDER should be ".cursor-server"

      • VSCODE_PATH should be "$(dirname "$(dirname "$(dirname "$(dirname "$(realpath "$0")")")")")"

        • Paths slightly differ from VS Code, so this extra dirname calls are necessary)
    • Fix the semi-invalid output from the call to Cursor as CLI in line 47

      • The cat /tmp/remote-wsl-loc.txt expects to only output a path, but it outputs 2 lines that breaks the script. To fix this, we forcibly get only the 2nd line:
        WSL_EXT_WLOC=$(cat /tmp/remote-wsl-loc.txt | head -2 | tail -1)
        

Cursor will now be correctly launched by whatever WSL instance invokes it:

20240219_014531.mp4 This is my current cursor file contents:

#!/usr/bin/env sh
#
# Copyright (c) Microsoft Corporation. All rights reserved.
# Licensed under the MIT License. See License.txt in the project root for license information.
if [ "$VSCODE_WSL_DEBUG_INFO" = true ]; then
	set -x
fi

COMMIT="56becd74fc3058ee97a0b2496d8ae7ad2c2fcb10"
APP_NAME="cursor"
QUALITY="stable"
NAME="Cursor"
SERVERDATAFOLDER=".cursor-server"
VSCODE_PATH="$(dirname "$(dirname "$(dirname "$(dirname "$(realpath "$0")")")")")"
ELECTRON="$VSCODE_PATH/$NAME.exe"

IN_WSL=false
if [ -n "$WSL_DISTRO_NAME" ]; then
	# $WSL_DISTRO_NAME is available since WSL builds 18362, also for WSL2
	IN_WSL=true
else
	WSL_BUILD=$(uname -r | sed -E 's/^[0-9.]+-([0-9]+)-Microsoft.*|.*/\1/')
	if [ -n "$WSL_BUILD" ]; then
		if [ "$WSL_BUILD" -ge 17063 ]; then
			# WSLPATH is available since WSL build 17046
			# WSLENV is available since WSL build 17063
			IN_WSL=true
		else
			# If running under older WSL, don't pass cli.js to Electron as
			# environment vars cannot be transferred from WSL to Windows
			# See: https://github.com/microsoft/BashOnWindows/issues/1363
			#      https://github.com/microsoft/BashOnWindows/issues/1494
			"$ELECTRON" "$@"
			exit $?
		fi
	fi
fi
if [ $IN_WSL = true ]; then

	export WSLENV="ELECTRON_RUN_AS_NODE/w:$WSLENV"
	CLI=$(wslpath -m "$VSCODE_PATH/resources/app/out/cli.js")

	# use the Remote WSL extension if installed
	WSL_EXT_ID="ms-vscode-remote.remote-wsl"

	ELECTRON_RUN_AS_NODE=1 "$ELECTRON" "$CLI" --locate-extension $WSL_EXT_ID >/tmp/remote-wsl-loc.txt 2>/dev/null </dev/null
	WSL_EXT_WLOC=$(cat /tmp/remote-wsl-loc.txt | head -2 | tail -1)

	if [ -n "$WSL_EXT_WLOC" ]; then
		# replace \r\n with \n in WSL_EXT_WLOC
		WSL_CODE=$(wslpath -u "${WSL_EXT_WLOC%%[[:cntrl:]]}")/scripts/wslCode.sh
		"$WSL_CODE" "$COMMIT" "$QUALITY" "$ELECTRON" "$APP_NAME" "$SERVERDATAFOLDER" "$@"
		exit $?
	fi

elif [ -x "$(command -v cygpath)" ]; then
	CLI=$(cygpath -m "$VSCODE_PATH/resources/app/out/cli.js")
else
	CLI="$VSCODE_PATH/resources/app/out/cli.js"
fi
ELECTRON_RUN_AS_NODE=1 "$ELECTRON" "$CLI" "$@"
exit $?

P.S.: Cursor ppl, hire me? lol

This is amazing! Thanks

can i ask you about your background and how you were able to debug this? @lesmo

OmarNaguib avatar Aug 29 '24 04:08 OmarNaguib

It's unbelievable this is still broken after so many months, and the fix is rather simple. Sadly Cursor is not open source... but here's a quick workaround based on VS Code's current launcher from WSL:

Caution

This will most likely break after Cursor gets an update. Hopefully they'll fix this in the next update, but if not these tweaks may need to be done again after every update.

Note

You should install the WSL Extension before attempting these steps

Important

I opened a WSL folder at least once before doing these steps. Doing so installed Cursor's WSL Server in ~/.cursor-server/bin. I'm not sure if this altered VS Code script would trigger that too if you directly run cursor without the WSL Server installed.

  1. Open the cursor linux script

    • Most likely located at C:\Users\<your user>\AppData\Local\Programs\cursor\resources\app\bin\

    • If you've installed the cursor command you can also:

      • Use which in WSL:
        $ which cursor
        /mnt/c/Users/lesmo/AppData/Local/Programs/cursor/resources/app/bin/cursor
        
      • Use where in Windows' Command Prompt:
        > where cursor
        c:\Users\lesmo\AppData\Local\Programs\cursor\resources\app\bin\cursor
        c:\Users\lesmo\AppData\Local\Programs\cursor\resources\app\bin\cursor.cmd
        
      • Use (Get-Command cursor).Source in PowerShell :
        > (Get-Command code).Source
        C:\Users\lesmo\AppData\Local\Programs\Microsoft VS Code\bin\code.cmd
        
  2. Copy the code linux script contents into the cursor one

    • Most likely located at C:\Users\<your user>\AppData\Local\Programs\Microsoft VS Code\bin\
  3. Patch the script with:

    • Cursor values for the variables:

      • COMMIT should have the value of the binary under ~/.cursor-server/bin, which for me right now is 56becd74fc3058ee97a0b2496d8ae7ad2c2fcb10

      • APP_NAME should be "cursor"

      • NAME should be "Cursor"

      • SERVERDATAFOLDER should be ".cursor-server"

      • VSCODE_PATH should be "$(dirname "$(dirname "$(dirname "$(dirname "$(realpath "$0")")")")")"

        • Paths slightly differ from VS Code, so this extra dirname calls are necessary)
    • Fix the semi-invalid output from the call to Cursor as CLI in line 47

      • The cat /tmp/remote-wsl-loc.txt expects to only output a path, but it outputs 2 lines that breaks the script. To fix this, we forcibly get only the 2nd line:
        WSL_EXT_WLOC=$(cat /tmp/remote-wsl-loc.txt | head -2 | tail -1)
        

Cursor will now be correctly launched by whatever WSL instance invokes it:

20240219_014531.mp4 This is my current cursor file contents:

#!/usr/bin/env sh
#
# Copyright (c) Microsoft Corporation. All rights reserved.
# Licensed under the MIT License. See License.txt in the project root for license information.
if [ "$VSCODE_WSL_DEBUG_INFO" = true ]; then
	set -x
fi

COMMIT="56becd74fc3058ee97a0b2496d8ae7ad2c2fcb10"
APP_NAME="cursor"
QUALITY="stable"
NAME="Cursor"
SERVERDATAFOLDER=".cursor-server"
VSCODE_PATH="$(dirname "$(dirname "$(dirname "$(dirname "$(realpath "$0")")")")")"
ELECTRON="$VSCODE_PATH/$NAME.exe"

IN_WSL=false
if [ -n "$WSL_DISTRO_NAME" ]; then
	# $WSL_DISTRO_NAME is available since WSL builds 18362, also for WSL2
	IN_WSL=true
else
	WSL_BUILD=$(uname -r | sed -E 's/^[0-9.]+-([0-9]+)-Microsoft.*|.*/\1/')
	if [ -n "$WSL_BUILD" ]; then
		if [ "$WSL_BUILD" -ge 17063 ]; then
			# WSLPATH is available since WSL build 17046
			# WSLENV is available since WSL build 17063
			IN_WSL=true
		else
			# If running under older WSL, don't pass cli.js to Electron as
			# environment vars cannot be transferred from WSL to Windows
			# See: https://github.com/microsoft/BashOnWindows/issues/1363
			#      https://github.com/microsoft/BashOnWindows/issues/1494
			"$ELECTRON" "$@"
			exit $?
		fi
	fi
fi
if [ $IN_WSL = true ]; then

	export WSLENV="ELECTRON_RUN_AS_NODE/w:$WSLENV"
	CLI=$(wslpath -m "$VSCODE_PATH/resources/app/out/cli.js")

	# use the Remote WSL extension if installed
	WSL_EXT_ID="ms-vscode-remote.remote-wsl"

	ELECTRON_RUN_AS_NODE=1 "$ELECTRON" "$CLI" --locate-extension $WSL_EXT_ID >/tmp/remote-wsl-loc.txt 2>/dev/null </dev/null
	WSL_EXT_WLOC=$(cat /tmp/remote-wsl-loc.txt | head -2 | tail -1)

	if [ -n "$WSL_EXT_WLOC" ]; then
		# replace \r\n with \n in WSL_EXT_WLOC
		WSL_CODE=$(wslpath -u "${WSL_EXT_WLOC%%[[:cntrl:]]}")/scripts/wslCode.sh
		"$WSL_CODE" "$COMMIT" "$QUALITY" "$ELECTRON" "$APP_NAME" "$SERVERDATAFOLDER" "$@"
		exit $?
	fi

elif [ -x "$(command -v cygpath)" ]; then
	CLI=$(cygpath -m "$VSCODE_PATH/resources/app/out/cli.js")
else
	CLI="$VSCODE_PATH/resources/app/out/cli.js"
fi
ELECTRON_RUN_AS_NODE=1 "$ELECTRON" "$CLI" "$@"
exit $?

P.S.: Cursor ppl, hire me? lol

working for me thanks !!!

Allengl avatar Aug 29 '24 14:08 Allengl

got

/mnt/c/Users/xxx/.cursor/extensions/ms-vscode-remote.remote-wsl-0.81.8/scripts/wslCode.sh: 63: /home/xxx/.cursor-server/bin/fee1edb8d6d72a0ddff41e5f71a671c23ed924b9/bin/remote-cli/cursor: not found

bilalbayasut avatar Aug 30 '24 04:08 bilalbayasut

I wish I had seen this before uninstalling vanilla vscode to get cursor up and running in WSL, uggh.

corticalstack avatar Aug 30 '24 06:08 corticalstack

Unacceptable bug, removed the app until this is fixed

xantorres avatar Sep 02 '24 15:09 xantorres

🤣 can't believe this is still broken after almost a year now

This is amazing! Thanks

can i ask you about your background and how you were able to debug this? @lesmo

@OmarNaguib just a software engineer, been doing this for a decade now... debugging is just like everything else: just follow the error messages and tweak things 'til it works 🤷‍♂️

lesmo avatar Sep 09 '24 16:09 lesmo

Worked for me, thanks

joacoesperon avatar Sep 11 '24 09:09 joacoesperon

You can try this:

  1. Open cursor, and connect to wsl
  2. Then run this fixWSL.sh in the wsl
#!/usr/bin/env bash

# Function to backup a file if it exists
backup_file() {
    local file_path=$1
    if [ -e "$file_path" ]; then
        mv "$file_path" "$file_path.bak"
    fi
}

# Function to safely copy a file and create a backup if it doesn't exist
safe_copy_with_backup() {
    local src=$1
    local dest=$2
    cp "$src" "$dest"
    if [ ! -e "$dest.bak" ]; then
        cp "$dest" "$dest.bak"
    fi
}

# Function to perform the sed replacements
perform_replacements() {
    local file_path=$1
    local bin_path=$2

    sed -i 's|APP_NAME="code"|APP_NAME="cursor"|' "$file_path"
    if [ -n "$bin_path" ]; then
        local commit
        commit=$(basename "$bin_path")
        sed -i "s|COMMIT=\"[^\"]*\"|COMMIT=\"$commit\"|" "$file_path"
    fi
    sed -i 's|NAME="Code"|NAME="Cursor"|' "$file_path"
    sed -i 's|SERVERDATAFOLDER=".vscode-server"|SERVERDATAFOLDER=".cursor-server"|' "$file_path"
    sed -i -E 's|VSCODE_PATH=".+"|VSCODE_PATH="$(dirname "$(dirname "$(dirname "$(dirname "$(realpath "$0")")")")")"|' "$file_path"
    sed -i -E 's|WSL_EXT_WLOC=(.+)|WSL_EXT_WLOC=$(tail -1 /tmp/remote-wsl-loc.txt)|' "$file_path"
}

# Main script execution
CODE_PATH=$(which code)
if [[ "$CODE_PATH" == *"cursor"* ]]; then
    backup_file "$CODE_PATH"
fi

CODE_WIN_PATH=$(which code)
CURSOR_WIN_PATH=$(which cursor)
BIN_PATH=$(ls -d ~/.cursor-server/bin/*/ 2>/dev/null | head -n 1)

safe_copy_with_backup "$CODE_WIN_PATH" "$CURSOR_WIN_PATH"
perform_replacements "$CURSOR_WIN_PATH" "$BIN_PATH"

Fixed it perfectly. Thanks for the easy fix

TexasCoding avatar Sep 13 '24 00:09 TexasCoding

thank you for breaking my dev setup wasted my 20 mins not using cursor

akshay-nm avatar Sep 15 '24 23:09 akshay-nm

This issue should be fixed in today's 0.41.1 release!

tmm1 avatar Sep 20 '24 17:09 tmm1