Linux desktop the “right way” š
Ultimately, a Linux – or any other for that matter – desktop is only as good as its configuration.
Everyone wants a desktop that can run as generically and efficiently as possible.
It is inevitable however, that as software evolves and more developers are involved, things can be overlooked, things that can, sometimes be trivial, sometimes detrimental to a running system.
As the means of talking to the operating system is the user shell, be it graphical or command-line, we will focus on a couple of tweaks that ought to have been set up properly by the distribution manager in any Linux distribution, but, are sometimes missed.
The $PATH
GNU/Linux, being an operating system, is a collection of executable programs (kernel included) and libraries that are organized in different parts of the filesystem.
Additionally, as part of both the system and the user environments, there are several common values held in “variables” that are referred to by many programs and make up the “environment”.
One of – if not the most important environment variable is the $PATH which is made up from the names of the directories that contain most of the system’s executable programs.
Typical directories that should be included in the $PATH are typically:
/sbin – Statically linked programs that can be used during system recovery.
/bin – Dynamically linked core programs, essential to system operation.
/usr/sbin – Statically linked optional programs and utilities.
/usr/bin – Dynamically linked optional programs and utilities.
/usr/local/sbin – Locally compiled, statically linked optional programs.
/usr/local/bin – Locally compiled, dynamically linked optional programs.
The correct structure of the $PATH should always start from the least significant to the most important, for instance for a normal (non-root) user:
/usr/local/bin:/usr/bin:/bin:/usr/local/games:/usr/games
For most everyday users, the above configuration of the $PATH variable is more than adequate.
For more technically minded users and developers the story is a little different. As all directories that live outside of one’s $HOME require root privileges in order to write data into them, it is wise to have an area that can be written by the user and be included in the $PATH.
For the above reason, the $HOME/bin directory comes into play. With this mechanism, any user can have programs that can run on the system without having to have root privileges. So a more functional $PATH for a user e.g.Ā andyĀ would be:
/home/andy/bin:/usr/local/bin:/usr/bin:/bin:/usr/local/games:/usr/games
Most distributions nowadays come with setting the $PATHĀ inĀ .profile and contains this piece of code to do so:
# set PATH so it includes user's private bin if it exists if [ -d "$HOME/bin" ] ; then PATH="$HOME/bin:$PATH" fi
and most desktop managers have mechanisms to read thisĀ $PATH and set it globally for the desktop environment.
It seems however, that not all desktop environments take heed of theĀ $PATH insideĀ .profile orĀ .bash_profile and a more robust way is needed.
An elegant way to overcome this, is by creating aĀ .xsessionrc file in ourĀ $HOME and put this code in:
if [ -d "$HOME/bin" ]; then {
PATH=$HOME/bin:${PATH##$HOME/bin:}
}; fi
export PATH
Substituting the line
PATH="$HOME/bin:$PATH"
inĀ .profile orĀ .bash_profile andĀ .bashrc
with:
PATH=$HOME/bin:${PATH##$HOME/bin:}
will prevent from duplicating theĀ $HOME/bin portion of theĀ $PATH

