1

I am having trouble adding current PATH permanently on my ubuntu server for a postgresql user.

Every time I ssh or restart the server I have to run export PATH="${PATH}:${HOME}/.local/bin", I am running a python script which will not work unless this command is done so I tried a a simple addition of this in python but it didn't solve.

import os
cmd ='''export PATH="${PATH}:${HOME}/.local/bin"'''
os.system(cmd)
... rest of my code

I also tried sudo export PATH="${PATH}:${HOME}/.local/bin" but it gets removed after each restart what can I do to permanently add this path or make the python script run it.

3
  • In your home directory (or the home directory of your server) there is a file called ".bashrc", which probably is what you are asking for. Nov 1, 2020 at 16:00
  • @GyroGearloose does it matter that I am doing it on postgresql user ?
    – User19
    Nov 1, 2020 at 16:01
  • "does it matter that I am doing it on postgresql user ?", yes, but not specifically. ".bashrc" in the respective home directory is executed every time an new bash shell is opened. (Similar *rc-files exist for other shells). For a test, use some thing like "touch /tmp/diditwork" in your .bashrc to check if it is executed or not. Nov 1, 2020 at 16:05

1 Answer 1

1

Add your path change to .bashrc perhaps

PATH="$PATH:$HOME/.local/bin"

Notice there is no export or other fancy stuff in the line

5
  • 2
    should not add the current directory in the path, ~/.local/bin is added automatically on existence from ~/.profile, and last, it's the wrong order, preferable is to have custom path first
    – user986805
    Nov 1, 2020 at 16:14
  • @bac0n Yes, that directory should be added to the path automatically if it exists when you log in. There an if then statement that adds this directory.
    – mchid
    Nov 1, 2020 at 16:27
  • 1
    @mchid the directory does exist why else would it work when I manually run the command. I believe the issue have to do with the fact that the use is a postgres user
    – User19
    Nov 1, 2020 at 16:50
  • @User19 Yes, I was wondering why it wasn't automatically working. The other place to add this is to your ~/.bashrc file like in this answer but you would have to log out and log back in to verify if it works.
    – mchid
    Nov 1, 2020 at 17:17
  • @mchid yes, it worked that way.
    – User19
    Nov 1, 2020 at 17:38

Not the answer you're looking for? Browse other questions tagged .