How do I edit the bash_profile? I've tried using the command chflags but it shows the error

[Error writing. Bash_profile: Operation not permitted]

I'm using OS X Snow Leopard 10.6.8.


In most cases, the file doesn't even exist unless you specifically create it. In order to do this, you don't need chflags. In fact, if you're a typical user, you don't need chflags at all with your Mac.

Just enter:

cd
touch .bash_profile

You can then edit it with whatever application you like, for example a terminal-based editor like vim, nano, or even TextEdit:

vim .bash_profile
nano .bash_profile
open -a "TextEdit" .bash_profile

After you've edited the file, make sure to source the .bash_profile again. Otherwise, bash won't recognize the changes:

source .bash_profile

If for some reason you don't have permissions, make sure your .bash_profile looks like this when doing a directory listing with ls -la – i.e. mode 644, owned by yourself.

charon:~ werner$ ls -l .bash_profile 
-rw-r--r-- 1 werner  staff  1323 Apr  4 18:00 .bash_profile