Linux: Change the PATH [ Add New Directory ]

How do I change the PATH settings under Linux operating systems and add a new directory to $PATH under bash shell?

You can change your PATH by editing your ~/.bash_profile file or ~/.profile file under Linux operating systems for your own login session. Open a command-line terminal (select Applications > Accessories > Terminal), and then type the following commands to edit ~/.bash_profile file:

vi ~/.bash_profile

To add /opt/apps and $HOME/bin/ directories to your PATH, append or modify the line starting with PATH:

export PATH=$PATH:/opt/apps:$HOME/bin

The “:” act as a separator to represent a list of directories. Save and close the file. Logout and login back to see your new path settings:

echo $PATH

Change the PATH For All Users On Linux

You can change the PATH for all users on the Linux system by editing the file /etc/profile file, enter:
# vi /etc/profile
To add /opt/apps directory to your PATH, append or modify the line starting with PATH as follows:

export PATH=$PATH:/opt/apps

Save and close the file.

🐧 Get the latest tutorials on Linux, Open Source & DevOps via RSS feed or Weekly email newsletter.

🐧 2 comments so far... add one

CategoryList of Unix and Linux commands
Disk space analyzersdf duf ncdu pydf
File Managementcat cp mkdir tree
FirewallAlpine Awall CentOS 8 OpenSUSE RHEL 8 Ubuntu 16.04 Ubuntu 18.04 Ubuntu 20.04
Modern utilitiesbat exa
Network UtilitiesNetHogs dig host ip nmap
OpenVPNCentOS 7 CentOS 8 Debian 10 Debian 8/9 Ubuntu 18.04 Ubuntu 20.04
Package Managerapk apt
Processes Managementbg chroot cron disown fg glances gtop jobs killall kill pidof pstree pwdx time vtop
Searchingag grep whereis which
User Informationgroups id lastcomm last lid/libuser-lid logname members users whoami who w
WireGuard VPNAlpine CentOS 8 Debian 10 Firewall Ubuntu 20.04
2 comments… add one
  • kracekumar May 15, 2012 @ 5:46

    No need to logout and login to check the details. `source ~/.bash_profile` and try `echo $PATH`

  • karthik Aug 8, 2014 @ 10:42

    I want to know about Permission and special permission.

Leave a Reply

Your email address will not be published.

Use HTML <pre>...</pre> for code samples. Still have questions? Post it on our forum