To add a directory to the PATH variable in Linux using the export command, follow these steps:
-
Open your terminal.
-
Use the
exportcommand to append the new directory to the existingPATH. For example, if you want to add/home/user/my_directory, you can do it like this:export PATH="$PATH:/home/user/my_directory" -
Verify the change by checking the
PATHvariable: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:
-
Open the configuration file in a text editor:
nano ~/.bashrc -
Add the
exportcommand at the end of the file:export PATH="$PATH:/home/user/my_directory" -
Save the file and exit the editor.
-
Apply the changes by running:
source ~/.bashrc
Now, the new directory will be included in your PATH variable every time you open a terminal.
