• VMware

    Learn about VMware virtualization for its products like vsphere ESX and ESXi, vCenter Server, VMware View, VMware P2V and many more

  • Linux

    Step by step configuration tutorials for many of the Linux services like DNS, DHCP, FTP, Samba4 etc including many tips and tricks in Red Hat Linux.

  • Database

    Learn installation and configuration of databases like Oracle, My SQL, Postgresql, etc including many other related tutorials in Linux.

  • How to set environment (PATH) variable permanently in Linux

    There is a time when every Linux Administrator gets stuck at a point of his career when he/she has to set a custom path or any other environment variable permanently in the Linux machine.

    Suppose you have added a new path to the PATH variable using the shell but you might observe that every time you switch terminal the PATH variable does not works.

    To make this issue to be resolved permanently you need to add the variable inside .bashrc or .bash_profile file inside the home folder of the user.

    For example, you want to add a PATH variable for root user so you need to add the path inside ~/.bashrc or ~/.bash_profile

    Now the confusion comes which file should we place the variable or inside both the files?

    Difference between .bashrc and .bash_profile

    Every time you login to a Linux (Red Hat) machine .bash_profile file is executed
    In case you are already logged in and you open a new terminal then .bashrc file is executed

    So, basically you can put the environment variable inside any of the two files. As per me I would advice you to put the same inside .bash_profile.


    Have a look at .bash_profile file
    # less ~/.bash_profile
    # Get the aliases and functions
    if [ -f ~/.bashrc ]; then
            . ~/.bashrc


    # User specific environment and startup programs


    export PATH
    export PATH=$PATH:/usr/local/samba/bin

    You can see in the highlighted part in blue in the above part, every time .bash_profile is executed it also runs .bashrc along with it. As you can see I have added an extra PATH variable for my samba so that I do not need to set it every time I log in.

    Sorry for the long post but just thought to clarify in the best possible way from my side.

    Related Articles
    How to mount windows share on linux

    Follow the below links for more tutorials

    Configure Red Hat Cluster using VMware, Quorum Disk, GFS2, Openfiler
    Tutorial for Monitoring Tools SAR and KSAR with examples in Linux
    How to configure Samba 4 Secondary Domain Controller
    How to secure Apache web server in Linux using password (.htaccess)
    How to register Red Hat Linux with RHN (Red Hat Network )
    Red hat Enterprise Linux 5.5 Installation Guide (Screenshots)
    15 tips to enhance security of your Linux machine
    Why is Linux more secure than windows and any other OS
    What is the difference between "su" and "su -" in Linux?
    What is kernel-PAE in Linux?
    What is swappiness and how do we change its value?
    How to log iptables messages in different log file
    What are the s and k scripts in the etc rcx.d directories
    How to check all the currently running services in Linux
    How to auto start service after reboot in Linux
    What is virtual memory, paging and swap space?

    How to set environment (PATH) variable permanently in Linux How to set environment (PATH) variable permanently in Linux Reviewed by Deepak Prasad on Saturday, December 28, 2013 Rating: 5


    Powered by Blogger.