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 11 months ago • 16 comments

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