Logo
← Back to Blog

Ubuntu Note

PATH in Ubuntu

Notes on how PATH is built in Ubuntu, where persistent and temporary changes come from, and how to make software available as a short command.

These notes summarize how PATH configuration is organized in Ubuntu and how I use it when setting up software and command line tools.

PATH structure

When you start a terminal session, PATH is built step by step from system settings, user settings, and temporary session changes.

01

System wide configuration

/etc/environment, /etc/profile, and /etc/profile.d/*.

02

User specific configuration

~/.bash_profile, ~/.profile, and ~/.bashrc.

03

Session changes

Temporary changes created by commands such as export PATH=....

System wide configuration

1. /etc/environment

  • Purpose: Defines system wide environment variables, including PATH.
  • Common usage: Contains important system paths such as /usr/local/bin and /usr/sbin.
  • Third party software: Rarely modified unless the software is installed system wide, for example Java, Docker, or Go.
  • Note: It is a simple key value file and does not support shell scripting.

2. /etc/profile

  • Purpose: A system wide shell configuration file executed for login shells.
  • Common usage: Sets PATH for global use or sources scripts from /etc/profile.d/.

3. /etc/profile.d/

  • Purpose: Contains shell scripts used for modular system wide configuration.
  • Common usage: Packages can modify or extend PATH without editing /etc/profile directly.

User specific configuration

1. ~/.bashrc

  • Purpose: Used for non login interactive shells, such as opening a terminal emulator.
  • Common usage: User customizations, aliases, functions, and paths for installed tools.
Bash
export PATH=$PATH:/home/user/.local/bin

2. ~/.bash_profile or ~/.profile

  • Purpose: Used for login shells, for example when logging in through SSH.
  • It can source ~/.bashrc so the settings remain consistent.
Bash
if [ -f ~/.bashrc ]; then
    source ~/.bashrc
fi

What happens when you modify PATH?

Persistent changes

Created by editing files such as .bashrc, .bash_profile, or /etc/environment. These changes remain across new terminal sessions.

Temporary changes

Created by running export PATH=... in the current terminal. They are lost when that session ends.

Create a short command for software

The original notes describe two ways to make a program easier to launch from the terminal.

Way 1: Create a symbolic link

If you have sudo privilege, create a symbolic link in /usr/local/bin.

Bash
sudo ln -s directoryOfRunningfile /usr/local/bin/filename

# Example
sudo ln -s /usr/local/MATLAB/R2019b/bin/matlab /usr/local/bin/matlab

sudo ln -s /path/to/original/file.txt /path/to/symlink.txt
For one user

The notes suggest using ~/.local/bin instead of /usr/local/bin.

Way 2: Extend PATH

If you do not have sudo privilege, add the software directory to PATH for the current session.

Bash
export PATH=$PATH:/usr/local/MATLAB/R2019b/bin

For a persistent user configuration, add the command to ~/.bashrc.

Bash
vi ~/.bashrc

Then reload the configuration.

Bash
source ~/.bashrc