EACCES: permission denied in VS Code MAC - visual-studio-code

When I change any file, the system will deny me access. What's going on?
How do I properly set permissions on Mac?

It is generally not a good idea to run VS Code as sudo. Instead change the permission for the directory.
You can change the ownership of the directory so that you can open it without needing root privileges.
$ sudo chown -R <user-name> <directory-name>

First, take note of the current permissions of all files and folders by issuing the command:
ls -lR <project_dir_name> > old_permissions.txt
which will save the output of the command ls -l <project_dir_name> to the file old_permissions.txt in the current directory.
If you have no idea of how permissions work and what the results of the previous command represent, please, have a look at https://ss64.com/bash/syntax-permissions.html and https://ss64.com/bash/chmod.html.
At this point, to modify any of the files under <project_dir_name>, you can give full permission to all subfolders and files recursively by issuing the command:
sudo chmod -R 777 <project_dir_name>
Note that you're responsible for the changes your perform!
After having saved the updates, you can reset the previous permission settings of the folders by looking at the old permissions saved in the file old_permissions.txt. You should set the permissions manually (unless you create e.g. a script to do it automatically using the info saved in old_permissions.txt).
Note: it's probably a better idea to only modify the permissions of the specific files that you want to modify (and not of the whole folder).

I managed to fix this on Mac while running this in Terminal
sudo chown -R $(whoami) /Users/$(whoami)/.vscode
hope this helps someone

Uninstall the code command from PATH in vscode and reinstall it.
Open the command pallete (command + shift + P), search "uninstall 'code'" and select the first option to uninstall.
Open the command pallete (command + shift + P), search "install 'code'" and click "Install 'code' command in PATCH

None of the above solutions solved this issue for me, here's what finally worked:
System Preferences > Security and Privacy > Privacy (tab) > (scroll down to) Files and Folders > Select Desktop Folder

I found a fix. I simply uninstalled the code command from PATH in vscode and reinstalled. i.e open the command pallete, search "uninstall 'code' command in PATH" and select the first option to uninstall. Then do the same to install it back "install 'code'...". Do same for installing too. That should fix it
https://github.com/microsoft/vscode/issues/129884
props to lazy-poet

cd to the project directory and
run cd .. to move back one folder
run sudo chmod -R 777 <project_dir_name>
it works for me vscode never asked me for password when saving my file again.

If you want to fix permissions for the current user use sudo chown -R $(whoami) ~/.vscode/.
$(whoami) is a variable with the current user that's logged in
~ is a shorthand for the home directory of the current user

Easy fix is: go to visual studio code and press cmd+shift+p and then the type 'uninstall code' select that option and reinstall it again with cmd+shift+p and type 'install code' and click.

Go to your project, double click on the app.js file and select 'Get info'. There will be an option of 'Sharing & Permission'. From there you can change access permissions for other users.

In my case, it turned out that the VSCode application was in the Downloads folder, and not in the Applications folder.
After I moved it to the Applications folder, I deleted the /usr/local/bin/code symlink. Then, I closed and re-opened VSCode, and hit Command+Shift+P and typed code which brought up Shell Command: Install 'code' command in PATH and successfully added code to the path!

I had a similar issue. I had error when I tried to create a new component. I just navigated to the path displayed in Finder. For me it was ProjectFolder/src/. So I did right click on "src" folder and selected "Get Info". In that change access to "Read&Write" for my user account. Thats it !!!
As you are trying to update a file, try to change access permission for that file (ie. app.component.css). If it didn't work try to change access for "app" folder.
Note: Changing the access of parent/super-parent folder won't work. So change the exact folder's access preferences.

In my case it was problems with mixed permissions within .git/objects directory. Some of them been my user, some - surprisingly - root.
This helped:
cd: .git/objects
sudo chown -R username:usergroup *
If mismatch with permissions occur not only within git objects but whole repo, chown command can be executed in upper directory.

This is the solution for me.
Open the Terminal and enter this command:
code --user-data-dir="./vscode-root"
This is for Ubuntu 16.04.

Go to your terminal and input the command:
sudo "/Applications/Visual Studio Code.app/Contents/MacOS/Electron" ~/.bash_profile
It works for me.
However, according to the answers on the websites, it is not recommended to get super user permission when you launch the vs code. I am new to vs code as well so I don't know the right method to get permission.
Besides, on my mac, you will get only permission once when you type in the command and after you exit your vs code, you will not possess the permission if you open the vs code again. I am still working on it and try to fix.
But this answer should fix your problem.

Here's the solution: You probably tried to save the file to "Macintosh Hd" which is the default place when you click on "Save as", so you can't just save a file to the computer inside itself, you have got to choose a directory, like you can save it to /Desktop or /users/your_username/... something like that. But saving to "Macintosh Hd" will always be unsuccessful.

I Fix this on my M1 mac using this command.
sudo chown -R <userName> *
This command will allow ownership to the user for all files.

The problem is, that you are probably trying to access a project which is owned by a another user e.g. the user which is not currently logged in.
You need to login as that user to work on the project.

Related

Set Permanent Flutter Path

The steps for modifying this variable permanently for all terminal sessions are machine-specific. Typically you add a line to a file that is executed whenever you open a new window. For example:
Determine the directory where you placed the Flutter SDK. You will need this in Step 3.
Open (or create) $HOME/.bash_profile. The file path and filename might be different on your machine.
Add the following line and change [PATH_TO_FLUTTER_GIT_DIRECTORY] to be the path where you cloned Flutter’s git repo:
$ export PATH="$PATH:[PATH_TO_FLUTTER_GIT_DIRECTORY]/flutter/bin"
Run source $HOME/.bash_profile to refresh the current window.
Verify that the flutter/bin directory is now in your PATH by running:
echo $PATH
In mac, you should add it as follows in ".zshrc":
export PATH="$PATH:/Users/matteo/Documents/flutter/bin"
After you have updated the ".zshrc" file, run this command to ensure changes have been notified to OS
source ~/.zshrc
Reference: https://flutter.dev/docs/get-started/install/macos
A similar concept is for Linux system using bash files
I tried a lot of methods but this one permanent solution worked for me like a charm:
open Terminal in your Mac: type:
sudo nano /echo/paths
Add the code to the file:
/users/yourUserName/flutter/bin
Save the file using Control+X and Press Y and Enter
Hope this helps! :)

bash: mongo: command not found

I installed mongodb on my system, but when I go to bin directory using Git and type mongo, this happens.
What shall I do?
The problem can solve if you add MongoDB path in the system variables:
Go to this path "Control Panel\System and Security\System" on the left you should see some options click on "Advanced system settings" after this click on "Environment Variables" at the System variables should be one option "Path" click that option and "Edit" it, add "New" variable on this system, in my case, is "C:\Program Files\MongoDB\Server\4.2\bin" and save this change.
if you're using git bash, use the following command
$ ./mongo
I've just had the same problem and did this to solve it. I hope it helps (late, but to be sure it is answered).
Open GitBash and type the following:
1) cd.. // to go to the root directory.
2) touch .bash_profile // creates a hidden file to set up the shortcut
3) notepad .bash_profile // this opens that hidden file with notepad. You can also do it with VIM if you want to master you command console skills...
4) paste these two command lines:
alias mongod="/c/Program\ Files/MongoDB/Server/4.0/bin/mongod.exe"
alias mongo="/c/Program\ Files/MongoDB/Server/4.0/bin/mongo.exe"
!!! Check that your files are also in the same route as these. If not, modify what's needed. Mind the space between "\ Files" because this gave trouble too. You may need to change the version in case you don't have 4.0.
5) Save the file. Close Notepad.
6) At Gitbash again: CRTL + C, and close the console.
7) Open Gitbash again, go to the root, and type: mongo --version. If you see something like: MongoDB Shell version v4.0.10... you've been successful (see image). If not, check the route of the document you've put into the bash profile, and be sure to fully restart the bash console after.
Mongo install success
Hope that helps!
Use mongosh intead of mongo.
This solved my problem using docker
In later versions of this, you have to download mongo shell. Once you downloaded if zip extracts the files and moved folder to your program's folder. Renamed the folder mongosh. Copy the path and added to your environment variables path. it should look like this C:\Program Files\mongosh\bin. Next, if you haven't done so already. Create data folder in your root directory in my case windows c drive. Create a subfolder in the data folder called db. make sure this folder is in the root directory and not in the program's folder. Once this is done, close all the prompt windows and run again mongod and again run now not mongo but mongosh, and it will allow you to type in your code. I had to delete my previous created data folder that i created previous to installation of MongoDB hope this helps.

Atom - Unable to save file: Permission denied (Windows)

I've been a long time user of notepad++ and I enjoy it a lot, but a friend recently recommended me to use Atom, so I gave it a try. However, when I try to save anything in my project folder (or any file at all), I receive this message that I am unable to save file: permission denied.
I've tried typing the command sudo atom /path/to/file in my PowerShell for Windows, but I get the following message:
I understand that sudo is a Linux-based command and thus would not work in a Windows environment but would there be an alternative route to get Atom working on my machine?
Thanks a lot!
The files were made "Read Only" somehow (maybe your anti-virus software or something, who knows...).
Solution:
Go to the folder in the Explorer, highlight all of the files in your project. Right click, open the properties. Deselect "Read-Only" and push ok. When it asks if you would like to apply to only the selected files or also to the files in any sub-folders, click yes if you need to.
This should fix your problem.

How to open folders in VSCode via Terminal in a fresh state?

It appears that VSCode always opens a folder in with the last UI state it had.
I'm looking for something like Sublime's remember_open_files: false, or in other words, I would like VSCode to open up with a clean UI state regardless of what state the UI was in the last time the folder was open.
What's happening now:
cd my-project-folder/
code .
# VSCode opens folder with saved UI state
What I want:
cd my-project-folder/
code .
# VSCode opens folder with fresh UI state
I tried to do it through command line using the command
code -n .
which should have opened VS code in current folder with a new session but it does not seem to work at all. I believe that code . seems to ignore the -n new session option and restores the previous session for the folder. So this feature is probably not implemented in VS code.
(Refer here for the commandline options for VS code.)
this is the command that works for me on windows
code -r .
From inside VS Code built-in terminal, cd into your project folder/directory and enter command:
code -a .
Note period at end.
This will open your current directory/project folder without opening a new window.
Part of the answer on this thread worked for me. Basically, make sure VSC is in the Applications folder. Then open the Command Palette (F1 or ⇧⌘P on Mac) and type shell command to find the Shell Command: Install 'code' command in PATH command.
Restart Visual Studio Code if it's open. In terminal, navigate to the folder you want to open in VSC, and type code .. Hopefully it should work for you.
If you are using a Mac, you need to first install the VSCode command amongst the shell command list.
Do this:
Open VSCode
press CMD + SHIFT + P
type shell command
select Install code command in path
navigate to any project from the terminal and type code .
code . opens VS Code at the current terminal folder
If you are using VS Code [Version: 1.50.0] then open your command prompt and go to your project's directory and just run the command:
code -a .
i.e. [Also can see the photo]
[1]: https://i.stack.imgur.com/sMmkH.png
$ code . --user-data-dir=.
This will open Visual Studio Code in current working directory. I use Bash with Ubuntu 16.04LTS.
I am using VS Code Version 1.24.1 (As of the time of original posting).
If you want to open a folder through the terminal, you can execute the command:
code -n name_of_your_folder/
or
code -n path_to your_folder/
Same thing goes for a file, and these open VS Code in a new window.
Also, note that you should have VS Code installed.
You're welcome!
I checked through all of the settings available in the VSCode preferences for me, and I don't think there is a way to do this.
There are some settings related to what VSCode window instance that folders will open into, but nothing that seems similar to Sublime Text's remember_open_files setting.
The closest thing I found was running code --user-data-dir . (feel free to replace . with some other directory so you don't pollute your current working directory) from the terminal to specify that VSCode shouldn't remember ANY previous settings, but this seems like overkill for what you're trying to accomplish (as VSCode will literally run as if it's the first time it's being run after a fresh install).
EDIT: I just discovered a View: Close All Editors command in the command palette (CMD + SHIFT + P). The keyboard shortcut for OSX is CMD + K, CMD + W, and this will close all the files you have opened!
I have the same problem on Mac.
I solved it in the following steps:
I opened the "Command Pallete" on the VSCode. This can be done by CMD + SHIFT + P
Type "shell"
Click on 'Install code command in path'
Give an administrator password
You will get a message that it has been installed
Now run "code ."
NB: Make sure you already cd into the folder you want to open before you run code .
If you want to open folder with vscode, you just go to folder ( you can user terminal or file explorer) with terminal, and do "code ."
To get the right folder in VS Code v 1.50.1 Terminal I tried a lot of options which didn't work for me. At the end I found very easy solution. I went to File->Open Workspace and found that my Workspace had the wrong folders inside it, which I simply deleted (from Workspace only!). Then I opened the folder I needed in my Workspace, opened Terminal->New Terminal, and everything worked perfectly well. Please let me know if this will work for someone else.
This command works to open a specific folder in VS code using terminal
code -r Documents/VS/C++/
here -r switch is used to open a file or a folder in an already opened VS code window
and then you specify the path of the file or folder you want to open
if you want to open it in a new window use -n switch instead of -r
This works for me with VSCode on Linux:
cd path/to/project
codium .
I tried every mentioned answers, what's work from me is this:-
I created a shell script to open folders.
$ sudo nano /usr/local/sbin/code2
/usr/bin/code-oss -n --user-data-dir '/home/myusername/.config/Code - OSS2/' -a $#
$ sudo chmod +x /usr/local/sbin/code2
You can remove --user-data-dir '/home/myusername/.config/Code - OSS2/' from the script if you want to use default code-oss config folder.
When I want to open a folder, I use the command like this :-
$ code2 .
I add this command code2 to open with option thunar to open folders directly from files manger.
Go to the directory in the command pallet on your computer the navigate to the the specific folder using cd
the type code . and that will open the folder and the files in it inside vs code. works like a charm.
If Visual Studio Code is installed using flatpak then a bash alias can help launch the application from the terminal.
alias code="flatpak run com.visualstudio.code"
I did it a simpler way just by three steps. I am currently in a project folder and want to open another folder in vs code using the cli or terminal. What I first did is navigated in the folder which I wanna open in vs code inside the terminal. Once I m inside that particular directory or folder I simply typed the command :
start code .
This will open that directory or folder in a new vs code window.
The complete process is :
open the terminal is vs code
navigate to the folder u want to open
once u r inside that particular folder type the command :
start code .

Eclipse, error: Couldn't write file "...." (permission denied)

I have a maven project on eclipse linked with a git repository. When I try to save files, eclipse tells me that it couldn't save the file because the permission is denied. I noticed that it happened after I remove some class from my project.
This is because according to your system, you are not the owner of the particular directory. If you are using ubuntu here is what you can do:
Login as root user to do this, in terminal enter command
"sudo su"
provide your password.
Then navigate till the directory and enter command
"chown -v user_name -R folder_name/"
This worked for me hope will do for you.