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.

sashoalm
  • 5,820
  • 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

3 Answers3

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.

HalosGhost
  • 4,790
sashoalm
  • 5,820
  • 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 09: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.

ranu
  • 147
  • 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 :) – ranu 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... – ranu 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 - http://unix.stackexchange.com/questions/131320/profile-is-not-sourced-in-debian-wheezy-lxde – sashoalm May 21 '14 at 13:10
  • And more, if you are logged as a user the echo $HOME would looks like: /home/yourUserName/. When you look at the .profile at the home directory in the final lines you can see that the script add the /bin if it exists. If its not your case I can paste the code for you. – ranu May 21 '14 at 13:11
  • I think the problem is I use lxdm - http://unix.stackexchange.com/a/90946/9108 – sashoalm May 21 '14 at 13:14
  • Yea, that's the problem :( – ranu May 21 '14 at 13:18
  • Try XFCE, it's cool :D – ranu May 21 '14 at 13:18
  • Advice worthy of a Windows support tech. If all else fails, make clean reinstall ;) But too late, I already solved the problem - http://unix.stackexchange.com/a/131327/9108 – sashoalm May 21 '14 at 13:22
  • Congrats hehe ;) – ranu May 21 '14 at 13:30
-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.

cioby23
  • 3,319
  • 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: http://unix.stackexchange.com/questions/124444/how-can-i-cleanly-add-to-path/ – 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
  • Check my updated answer for running programs using Alt+F2 – cioby23 May 21 '14 at 13:51