Permission denied to make changes to .bash_profile

I’m working through the Command Line course and decided to try out this activity, editing .bash_profile on my own machine.

https://www.codecademy.com/courses/learn-the-command-line/lessons/learn-command-line-environment/exercises/configuring-environment-bash-profile

However, when I try to edit .bash_profile with nano in Terminal, I get Permission Denied and can’t save changes. I am running Mac OS 11.1 Big Sur and I know it has Z shell / .zsh . I have Anaconda installed to run Python.

Error appears at the point of using ^O to write out. "Error writing /Users/my_name/.bash_profile: Permission denied "
Should I be able to do this? I’m very new to Command Line so please be gentle!

1 Like

Yeah, you should probably have read/write permission for your own home folder. You can double check the permissions/ownership either with ls -l or you can find the folder in finder right-click and select get-info (permission are near the bottom of the info window).

It’s worth noting that z-shell won’t necessarily be set up to source .bash_profile. See below for the files you want to sort out-

Edit: For zsh, here’s a helpful discussion of where to put what on OSX-

2 Likes

Thank you. Permissions for .bash_profile and another one with a similar name look like this:

-rw-r--r--    1 root       staff    447  8 Jun  2020 .bash_profile
-rw-------    1 kateohara  staff  12288 19 Jan 12:59 .bash_profile.swp

I have a .zprofile . Its permissions look like this, and it lets me edit and source. I’ve managed to apply that change.

-rw-r--r-- 1 kateohara staff 164 3 Jun 2020 .zprofile

I do notice that .bash_profile has some Conda-related stuff in it. .zprofile contains some $PATH stuff for Python 3.

Should I mention this in feedback, I wonder? There is mention of Z shell at the beginning of the course and it says you mostly won’t need to change.

What are the implications of this? Do I need to know anything? Just use .zprofile in future?

1 Like

Ahh. The issue is that .bash_profile already exists and is owned by root. Since you’re using zsh anyway it doesn’t matter but you may want to take ownership of that file (look into chown) or you’d have to start your text editor using sudo every time you wanted to change that file.

I think the biggest implication for you at this moment is that conda might try and use bash instead of zsh (since .bash_profile is altered that seems to be the case) which may potentially give you a headache with your path.

See conda’s install guides for how to deal with this (it mentions Catalina but I’m pretty sure this goes for Big Sur too; it’s a zsh vs. bash issue)-

Yes, it seems reasonable to raise it as an issue (instructions out of date). This has been a problem since Catalina, let alone Big Sur. The community section of the forum has a comments/feedback section.

1 Like

That’s really helpful, thanks.

Wondering if there is a way to check if conda is using zsh, I had a look in the .bashrc and .zshrc and this time there is nothing in bash but all the conda stuff there in zsh.

When I first installed Python I had no idea what I was up to and had to have a couple of tries so I wonder if the info in bash_profile is from an old installation. Everything is working.

I’ll put something in feedback about mentioning the zsh zprofile difference.

If you can type conda activate in the terminal and it works fine then I’d guess zsh is set up correctly. You should see (base) appear to the left of your prompt (you can use deactivate afterwards to finish with the virtual environment). The main difference is that it alters a shell config file (.profile or similar) to let you use conda commands directly in the shell (it’s largely for convenience).

Running the conda init zsh line should’ve altered ~.zshrc (or a similar file, I’m not 100% sure for OSX) so you can hunt down any possible changes.

1 Like

100% into things I don’t properly understand here, but the stuff (conda init stuff) that’s in .bash_profile is the same stuff that’s in .zshrc, so I think that suggests that conda has done what it needs to do to work in zsh, doesn’t it.

Have also noticed that Z Shell is starting up with conda activated, but I can deactivate and reactivate no problem. I don’t understand what that means yet (I have a notion) but I think it’s OK.

Thank you @tgrtim for taking the time to help with this issue, which is beyond the scope of Codecademy content!

1 Like