How to add to bash $PATH permanently on Linux

How to add to bash $PATH permanently on Linux

To permanently add a directory to the $PATH variable in Bash on Linux, you can follow these steps:

  1. Open the .bashrc file in a text editor. This file is located in your home directory (e.g., /home/username/.bashrc).

  2. Add the following line to the end of the file, replacing /path/to/directory with the actual path of the directory you want to add to the $PATH variable:

r‮ refe‬to:lautturi.com
export PATH=$PATH:/path/to/directory
  1. Save the file and exit the editor.

  2. Run the following command to reload the .bashrc file and apply the changes:

source ~/.bashrc

You can now use executables located in the directory you added to the $PATH variable without specifying the full path to the executable.

Note: The .bashrc file is only read by Bash when you start a new terminal session or when you run the source command. If you want the changes to take effect in all terminal sessions, you can also add the same line to the /etc/environment file. This file is read by all processes on the system and is used to set environment variables for all users.

Created Time:2017-10-28 21:38:58  Author:lautturi