Categories
Linux Tutorial Series

Linux Tutorial Series – 85 – Permanent changes to your environment via .bashrc

Here is the video version, if you prefer it:

If you want to make permanent changes to your environment, here is how to do it:

In virtually all use cases, you should modify .bashrc file located in your home directory (i.e. /home/mislav/.bashrc). The reason for that is that both login shells and interactive non-login shells read these files explicitly (and execute the commands within them). (“Why is /etc/profile not invoked for non-login shells?,” n.d.)⁠

Here are some lines I have added (appended) to my .bashrc file (in /home/mislav/.bashrc):

# added for Python

export PATH=$PATH:~/Python-3.7.4/bin

# added for Java

export PATH=$PATH:/usr/lib/jvm/jdk1.8.0_231/bin:/usr/lib/jvm/jdk1.8.0_231/db/bin:/usr/lib/jvm/jdk1.8.0_231/jre/bin:/home/mislav/Downloads/hadoop-2.10.0/bin:/home/mislav/Downloads/hadoop-2.10.0/sbin

These are the lines I added. They add certain directories to my PATH variable. The general syntax for adding to my PATH variable is:

export PATH=$PATH:newPath

where newPath is a path (or multiple paths delimited by a colon) where I want to look for executables. The $PATH get substituted for the contents of the variable PATH.

When writing this article, I found myself Googling quite a lot to make sure I really understood what files were read by what kinds of shells. A really great read on this is found here: (“Why is /etc/profile not invoked for non-login shells?,” n.d.). The main thing I got from the aforementioned reference is to place all of my changes in .bashrc, but it is such a great answer that I would urge you to read it if you have the time.⁠

Hope you learned something useful!

References

Why is /etc/profile not invoked for non-login shells? (n.d.). Retrieved February 7, 2020, from https://askubuntu.com/questions/247738/why-is-etc-profile-not-invoked-for-non-login-shells

NewsletterUpdates on interesting things I am doing

Subscribe to my newsletter to keep abreast of the interesting things I'm doing. I will send you the newsletter only when there is something interesting. This means 0% spam, 100% interesting content.

Leave a Reply

Your email address will not be published.