VS Code Denied Permission unlink 'usr/local/bin/code' - visual-studio-code

I can add the "shell command install 'code' command". Testing it works, but if i close out of the VS Code or after a couple of hours of adding the command it doesn't work. Terminal says "zsh: command not found: code" and on VS when click on the "shell command install code command" has a "EACCES: permission denied, unlink 'usr/local/bin/code' " pop up. How should i go about this? I'm using a macbook 2020 if that matters

Uninstall the code command from PATH in VS Code and reinstall it.
Open the command palette in VS Code using cmd + shift + p. Search "uninstall 'code'" and select the first option to uninstall.
Once uninstalled, "install 'code'" for installing.
That should fix it.

This happened to me on Macbook Pro M1 Chip. Basically follow this:
Simply uninstall the code command from PATH in vscode and reinstalled. i.e open the command pallete, search "uninstall 'code'" and select the first option to uninstall. Do same for installing too. That should fix it.
Found this solution on github

Try run:
sudo chown -R yourUsername /usr/local/bin

This command solves user just for copy paste.
sudo chown -R $USER /usr/local/bin

From a sample size of me and three friends, this is a common problem on M1 MacBooks and Mac Minis. Running the command:
sudo chown -R yourUsername /usr/local/bin
This resolved the VS issue for me and allowed me to install npm packages globally.

For Mac I have run below steps in my terminal and it resolve my issue.
you can also Try:
Open terminal.
sudo chown -R your_user_name /usr/local/bin
Open visual studio code.
use keybord command + shift + p
Type the bellow command.
install 'code'
Vs Code
For test go to terminal and run code .

I've run into this a few times on before. Steps I took to that fixed it for me:
open vs code and press cmd + shift + p to open the command palette
search for uninstall 'code' and press Enter
lastly, search for install 'code' and press Enter

For macOS:
Try uninstalling and reinstalling. (command + shift + p) >shell Command: Uninstall 'code' command from Path
append the following to your ~/.bash_profile file (~/.zshrc in case you use zsh).
code () { VSCODE_CWD="$PWD" open -n -b "com.microsoft.VSCode" --args $* ;}

I was getting same error to Install on Windows 11:
Just deleted folder C:\Users\my-username\AppData\Local\Programs\Microsoft VS Code\bin
Also removed VS Code from environment variables
Installed successfully!

for any mac users, you can try
sudo rm -f /usr/local/bin/code
That should help. It's important to note that you should be careful using sudo, since you can do a lot of damage in files and folders with it. But in the most dire instances, you should use it, similar to using any kind of --force commands, you should not use it often.

Related

How to open "vscode" and "zsh in vscode" using terminal?(already install shell code command in path in VsCode)

I just want to open vscode in terminal and I already install shell code command in path in vscode, I restart terminal by quitting and open and I have my vscode download in Mac not in application cause when I move vscode to application it won't open and I have to move vscode to trash and redownload it again, do I have to also restart my computer?
vscode
Shift + Command + P
shell command install 'code' command in path
Start with pwd in terminal
pwd
For open zsh in vscode:
code ~/.zshrc
zsh: command not found: code
For open vscode:
code
zsh: command not found: code
For check out vscode version in terminal:
code -v
zsh: command not found: code
Youtube search: vscode in macbook
Found this:
How to Install Visual Studio Code on Mac
https://www.youtube.com/watch?v=tCfbi5PF1y0
Btw this is the long way, the short way is to:
Open the Command Palette (Cmd+Shift+P) and type 'shell command' to find the Shell Command: Install 'code' command in PATH command.
Website:
https://code.visualstudio.com/docs/setup/mac
the reason for vscode not open cause of the data confuse which cause the vscode to not open, to solve the vscode not open when you put vscode in application, you basically have to redo the uninstall & install again, below are todo list if you are having the same problem:
step 1 uninstall and install vscode
step 2 move vscode from download to application
step 3 open vscode in launchpad
Step 4 uninstall & Shell Command: Install 'code' command in PATH command.
step 5 quit terminal and open it again
step 6 use the command line in above question to check if it work
Start with pwd in terminal:
pwd
code
code -v
code ~/.zshrc

Blank window vscode as root

it's been a long time that i run vscode as root via this command (ubuntu 20.04.4 LTS) :
> sudo code --user-data-dir="~/.vscode-root"
Today, i used the same command to execute vscode as root, but i don't have the same result.
in this time, i have a blank window.
i tried to remove it + remove /$Home/Code and .vscode folder
install it again but i have the same problem,
i tried to use the same command with other flags without being able to solve it.
Flags tried : --disable-gpu /// --disable-features=CalculateNativeWinOcclusion
is there a way to delete (package + config) and all data of vscode to install it properly again ?
screen shot
Any idea ?
Thank you & have a nice day
That works for me on VSCodium:
sudo su -c "codium --user-data-dir="/root" --no-sandbox && sleep infinity"
For some reason, vscode does not start with sudo, but it works calmly with su -c
PS: I do not know if it can be done easier. I needed this to work with git in vscode

"Unable to resolve your shell environment"

On macOS Big Sur, I installed MacPorts and installed bash using it. I set my default shell to the MacPorts version of bash /opt/local/bin/bash by using chsh.
All was well.
I decided I would rather use Homebrew. I uninstalled MacPorts, installed Homebrew, installed bash via homebrew, and set my default shell to /opt/homebrew/bin/bash via chsh.
All was well, except when I am first starting vscode (from Finder) which reports:
Unable to resolve your shell environment: A system error occurred (spawn /opt/local/bin/bash ENOENT)
This is a totally reasonable complaint, since that binary no longer exists. It makes this complaint when launched from Finder, but not when launched from the terminal. There is no reference to this prior version of bash in my user settings.json file, nor is it in my .bashrc.
Where the heck could vscode be getting this path to bash from?!
Edit (2021-10-11): there is something strange going on here. If I open an integrated terminal in vscode:
$ echo $SHELL
/opt/local/bin/bash
$ ls -lh $SHELL
ls: /opt/local/bin/bash: No such file or directory
$ ps -p $$
PID TTY TIME CMD
45388 ttys001 0:00.12 /bin/bash -l
(there are no such problems in the regular macOS Terminal app)
Edit again (2021-10-12):
I tried resetting vscode (via rm -rf ~/Library/Application\ Support/Code).
I tried resetting vscode's cache (via rm -rf ~/Library/Caches/com.microsoft.*),
I downloaded iTerm2 and ran it; it loaded the correct shell (/opt/homebrew/bin/bash) without issue (tried this in hopes of determining if there was some other setting in macOS pointing at the old macports version of bash).
Had the same issue and was able to resolve this by changing the shell for the logged in user (using chsh -s, cf. the hint at the bottom of https://github.com/microsoft/vscode/issues/139867). As this change is not being picked up by VSCode in your currently logged in session, don't forget to explicitly log out and log back in again after performing this step.

Fail to open vscode in WSL bash on ubuntu using cmd code

When I tried to open vscode in WSL bash on Ubuntu 20.04 using command code ., it failed and the following message was logged:
/mnt/c/Users/john/.vscode/extensions/ms-vscode-remote.remote-wsl-0.50.1/scripts/wslCode.sh: 57: /home/john/.vscode-server/bin/d2e414d9e4239a252d1ab117bd7067f125afd80a/bin/code: not found
I would like to ask how to fix this problem? Thx a lot!
I found the solution. Even though I think that you've already know it.
You need to delete the folder /home/john/.vscode-server/ with sudo rm -rf /home/john/.vscode-server.
Then, you just run code . or try to open any project that you want it.
Then a script will load and will install a new .vscode-server in your machine with the right files.

error while installing python extensions " can't open file 'directory + filename': [Errno 2] No such file or directory "

I tried to install mypy extension in vs code but it keeps showing me this error below
C:\Users\Yourusername\Dev\django_project_boilerplate\env\Scripts\python.exe: can't open file 'c:UsersYourusername.vscodeextensionsms-python.python-2020.6.89148pythonFilespyvsc-run-isolated.py': [Errno 2] No such file or directory
(env)
then I realized that the terminal is removing the anti-slashes from the file location in the commande below because it's a special character
c:/Users/Yourusername/Dev/django_project_boilerplate/env/Scripts/python.exe c:\Users\Yourusername\.vscode\extensions\ms-python.python-2020.6.89148\pythonFiles\pyvsc-run-isolated.py pip install -U mypy
I got the same error when clicking the "Install ipykernel" on the pop-up window when trying to use Python Interactive mode in VS Code.
My problem was that I had git bash as my default shell while running VS Code on Windows, hence filepaths where not being processed properly.
I solved the problem by changing my Terminal's default shell:
Type: ctrl + shift + p
In the dropdown, select Terminal: Select Default Shell
In the subsequent dropdown, select Command Prompt C:\...
Try running Interactive mode once again (e.g. add # %% above a line of code and then click Run Cell)
Now click "Install ipykernel" on the pop-up window that comes up on the bottom right corner.
The installation now executed from the cmd shell without any problems, and Interactive mode worked fine.
what I did is to add an extra anti-slash and it worked fine :
c:/Users/Yourusername/Dev/django_project_boilerplate/env/Scripts/python.exe c:\\Users\\Yourusername\\.vscode\\extensions\\ms-python.python-2020.6.89148\\pythonFiles\\pyvsc-run-isolated.py pip install -U mypy
For as I also use git bash as my default terminal in windows, I used the following command:
python /c/Users/uname/.vscode/extensions/ms-python.python-2021.3.680753044/pythonFiles/pyvsc-run-isolated.py pip install -U black --user
Whereas I was getting error like this, before:
C:/Users/uname/AppData/Local/Programs/Python/Python38/python.exe c:\Users\uname\.vscode\extensions\ms-python.python-2021.3.680753044\pythonFiles\pyvsc-run-isolated.py pip install -U black --user
C:\Users\uname\AppData\Local\Programs\Python\Python38\python.exe: can't open file 'c:Usersigour.vscodeextensionsms-python.python-2021.3.680753044pythonFilespyvsc-run-isolated.py': [Errno 2]
No such file or directory
As you can see it is due to the way git bash handles the file location differently, which I fixed and it worked fine alter.
Honestly, I love to see windows start following the same directory structure like other Linux system(Hope some day this will become true).
Change your vs code's terminal back to Default Shell > Command Prompt C:\Windows...
The error is due to PATH conflict while using git bash as default terminal on VS Code.