5

At the end of .bashrc file I added these lines to set path to foo folder in my home directory:

PATH = $PATH:/home/username/foo
export PATH;

Then I typed in bash:

source .bashrc

These produced error:

bash: PATH: command not found

I am using Debian Squeeze. In a similar question here it was advised to modify /etc/login.defs. I don't want to do this as in the very login.defs it is written:

add the rest [of your paths] in the shell startup files

How to add folder foo to PATH in .bashrc?

Community
  • 1
  • 1
cpp
  • 3,743
  • 3
  • 24
  • 38

3 Answers3

29

You are using the wrong syntax. Drop the spaces:

export PATH=$PATH:/home/username/foo

Regarding /etc/login.defsor any other global configuration: Well, it is global configuration, so probably a bad idea to add paths within your $HOME directory there. ;)

nmaier
  • 32,336
  • 5
  • 63
  • 78
3

Just use the following line in your .bashrc

export PATH=/home/username/foo:$PATH
  • 1
    If I don t remember bad.. It is a good practice put first $PATH. it avoids to overwrite native linux commands. – carlos.baez Jul 03 '20 at 22:37
  • Correct. `export PATH=$PATH:/home/username/foo` is better for preventing any unintentional overrides. – mehtabsinghmann Feb 03 '22 at 11:31
  • If the goal of adding custom executable binaries on the PATH is to override/wrap native functions/binaries, use the 'export PATH=/home/username/foo:$PATH' . If the goal is to append to the PATH only without overriding any native executable commands, use 'export PATH=$PATH:/home/username/foo'. Alternatively, the user could namespace the custom binaries to avoid any overrides due to precedence order from configuration files, like .bashrc in this case. – mehtabsinghmann Oct 10 '22 at 17:44
-1

There are differences in syntax between the one used on mac and CentOS, however on CentOS and RedHat the following syntax is being used.

export PATH="/path/directory:$PATH" then do source .bashrc

I am not sure about other distributions of Linux but it will work on CentOS and RedHat.

dferenc
  • 7,918
  • 12
  • 41
  • 49