How do you add a directory to the PATH variable in Linux using the export command?

0153

To add a directory to the PATH variable in Linux using the export command, follow these steps:

  1. Open your terminal.

  2. Use the export command to append the new directory to the existing PATH. For example, if you want to add /home/user/my_directory, you can do it like this:

    export PATH="$PATH:/home/user/my_directory"
  3. Verify the change by checking the PATH variable:

    echo $PATH

Making the Change Permanent

To make this change permanent (so it persists across terminal sessions), you can add the export command to your shell's configuration file, such as ~/.bashrc or ~/.bash_profile:

  1. Open the configuration file in a text editor:

    nano ~/.bashrc
  2. Add the export command at the end of the file:

    export PATH="$PATH:/home/user/my_directory"
  3. Save the file and exit the editor.

  4. Apply the changes by running:

    source ~/.bashrc

Now, the new directory will be included in your PATH variable every time you open a terminal.

0 Comments

no data
Be the first to share your comment!