Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

sudo open -e ~/.bash_profile Permission denied mac

I am trying to edit bash_profile file to add path to my sdk through the following command on my mac machine. sudo touch ~/.bash_profile; open -e ~/.bash_profile

It opens the file in TextEdit but does not allow me to edit it. Though i have given super-user permission and password while running the above command. It is giving me following message when i try to edit it.

"You don’t own the file “.bash_profile” and don’t have permission to write to it. You can duplicate this document and edit the duplicate. Only the duplicate will include your changes." I am new to mac. So please elaborate your answers.

like image 669
FarheenP Avatar asked Jan 21 '15 10:01

FarheenP


People also ask

How do I fix permission denied terminal Mac?

Open System Preferences ▸ Security & Privacy.Select the Privacy tab. Select Full Disk Access, then click the lock icon to activate the +/- add your Terminal.

How do I open bash_profile in Mac?

Press Command + Shift + Period (.) to see the hidden file. Select . bash_profile, fix your problem and save it accordingly.

Why is bash permission denied?

Usually, you get the error bash permission denied when running some script/file that does not have execute permissions. It is one of the most common Magento errors. All you need to do to fix it is to change file permissions and add executive one.

How do I open a bash profile?

###Text Editor Method: Open up Terminal and enter in open -e . bash_profile . This will open your profile in a simple text editor.


2 Answers

For Mac User Catalina,

.bash_profile not open, they need grant permission to edit this file. You can achieve by below steps

1) Open the terminal and enter below command ex: sudo chown iMac ~/.bash_profile

sudo chown {your username} ~/.bash_profile

2) Open editor in the terminal, here i used nano

nano .bash_profile

3) Edit your text you want.

4) To save the changes you've made, press Ctrl + O

5) To exit nano, press Ctrl + X

6) And finally to load your changes, enter below command

source .bash_profile
like image 80
Hitesh Avatar answered Oct 12 '22 23:10

Hitesh


The problem is that the file isn't owned by your user, but by root. You need to change the owner of the file to your user, then you can open and edit the file without the use of sudo:

sudo chown farheen ~/.bash_profile

This will, as the super-user, change the owner of the file back to you.

like image 31
Some programmer dude Avatar answered Oct 13 '22 01:10

Some programmer dude