I want to edit my $PATH environment variable. According to several tutorials and other sources (e.g. this Q&A), the most common way is to edit ~/.profile. However, for me, no such file exists. What can I do? (Are there different names on some systems? Should I create it? What needs to go in there? Are there other ways?)

I am a user on a network cluster, obviously I don't want to edit any global environment variables. I've edited ~/.bashrc before to change some stuff for my user, and there are several ~/.-files, but not ~/.profile.

I'm on Ubuntu 16.04.2 LTS Codename: Xenial. echo $PATH gives me only some global bin-directories, but after installing some user specific bins (to /path/to/home~/expanded/.local/bin/) I just want to add this to the PATH.

  • A .local (a hidden directory) in your $PATH is poor taste IMHO. Better use $HOME/bin which might even be "automatically" added on some distributions (but you need to login again) Oct 9 '17 at 10:15
  • 2
    @BasileStarynkevitch See unix.stackexchange.com/questions/370943/…
    – Kusalananda
    Oct 9 '17 at 10:21
  • @BasileStarynkevitch Thank you for your advice. As the excellent pointer from Kusalananda suggests, I'm setting up python which uses .local/bin by default.
    – Honeybear
    Oct 9 '17 at 11:04

If you have a ~/.bash_profile file, then edit that instead (since you seems to be using bash (since you are on Linux and since you mention that there is a ~/.bashrc file present that you've edited before)). The bash shell will only try to read ~/.profile if ~/.bash_profile does not exist. If neither file exists, you may create ~/.bash_profile.

The line you are likely to want to add is




depending on whether you want/need the added directory to be searched first or last.

There is no need for export as the PATH variable is already exported.

$HOME is the same as ~, but is IMHO more expressive in shell scripts. It also behaves as a proper variable whereas ~ does not. See e.g. Why doesn't the tilde (~) expand inside double quotes?

Also note that paths are delimited with forward slash (/) on Unix, not backslash (\), so you want ~/.bash_profile and not ~\.bash_profile.

Most sh-like shells (of which bash is one) reads .profile in the user's home directory when started as a login shell. This is why the answer that you linked to mentions .profile rather than .bash_profile; the specific shell used was not mentioned in the question.

Some shells, like bash, will ignore it if their own special startup file is present.

  • 1
    Thanks a lot for this comprehensive answer. I corrected the backslashes to forward-slashes in the paths. Bad habit back from using Windows.
    – Honeybear
    Oct 9 '17 at 11:06

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.