8

In Ubuntu, if $HOME/bin exists, it will be automagically added to PATH, but this doesn't happen in Debian.

How do I permanently add it to PATH for a given user, but only for him, not for all users? I want it to be valid for GUI programs also, not just for the terminal.

Edit: To clarify, I use LXDE, and from a login manager, i.e. not startx. .bashrc does not work for programs I start outside a terminal.

  • Note: Since you speak in the third person, there is a possibility that the user is not you. Then it is considered rude to modify his settings yourself (unless he asked it explicitly, of course). – fkraiem May 21 '14 at 12:20
  • Don't worry, the user is me. – sashoalm May 21 '14 at 12:25
8

It turned out that lightdm (the login manager LXDE now uses) does not source ~/.profile.

What worked for me was creating ~/.xsessionrc:

if [ -d $HOME/bin ]; then
    export PATH="$HOME/bin:$PATH"
fi

You can also add this to /etc/X11/Xsession.d/90userbinpath if you want all user to benefit from this (each user would benefit for his own path) with a system-wide configuration.

  • 2
    Or you could source the whole .profile file (which might do more than just set $PATH): if [ -f $HOME/.profile ]; then source $HOME/.profile; fi – basic6 Jun 14 '15 at 9:34
1

You can try the /etc/profile.

nano /etc/profile

There will be two kinds of PATH, the path for the root, and the path for normal users, non-root. So you just add to the root or normal users the /$HOME/bin on the final of the line Ctrl+O and Ctrl+X and there you go :). Remember that you need root to do this operation.

Or, you can go to your home and look at the .profile there.

cd /home/YOURUSERNAME
nano .profile

In debian it automatically does it too(add the bin to the path). Do a echo $HOME to see what home is.

  • That would be global for all users, I specifically pointed out "for a single user". Wouldn't it be better to use ~/.profile instead? – sashoalm May 21 '14 at 12:46
  • @sashoalm, edited :) – Rafael Campos Nunes May 21 '14 at 12:47
  • OK, but .profile doesn't seem to be executed at all. Is it the correct file to use? echo $PATH does not show my changes, even from a terminal. I don't have ~/.bash_profile or ~/.bash_login. – sashoalm May 21 '14 at 12:52
  • Try to exit your session and make a login again, well I don't know if it is the correct file to use, but every user has one, so it would be the answer for your question... – Rafael Campos Nunes May 21 '14 at 13:08
  • Yes, I did that, but it doesn't seem to be read at all. I posted a new question about that - unix.stackexchange.com/questions/131320/… – sashoalm May 21 '14 at 13:10
-1

In your ~/.bashrc file add the following line:

PATH=$PATH:$HOME/bin

Save it and then source the file to take effect.

source ~/.bashrc

You can check then by running

echo $PATH

For running GUI programs from Run command window (Alt + F2) create a new empty .xsession file in your home directory and add these lines:

#!/bin/bash -l
PATH=$PATH:$HOME/bin

Save it and reload your LXDE session. I have tested by moving xterm in $HOME/bin directory and call it with Alt+F2 and in started successfully.

  • This will work for a X session/GUI programs, not just for terminal, right? – sashoalm May 21 '14 at 12:12
  • This will work for both cases GUI and terminal. – cioby23 May 21 '14 at 12:13
  • OK, I thought GUI programs don't inherit from .bashrc, unless started from a terminal. – sashoalm May 21 '14 at 12:17
  • Beware you could end up adding $HOME/bin to the end of $PATH multiple times this way: unix.stackexchange.com/questions/124444/… – goldilocks May 21 '14 at 12:27
  • OK, .bashrc doesn't work - it seems to work only for programs I start from xterm, but not for programs I start using "Alt+F2", i.e. from LXDE (the DE I use). The DE uses a login manager, not startx. – sashoalm May 21 '14 at 12:35

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.