How to permanently set $PATH on Linux/Unix

Cover Image for How to permanently set $PATH on Linux/Unix
Matheus Mello
Matheus Mello
published a few days ago. updated a few hours ago

How to Permanently Set $PATH on Linux/Unix 🚀

Have you ever encountered the frustrating issue of having to reset your $PATH variable every time you start a new session in Linux or Unix? Fear not, for I have the solution you seek! In this guide, I will walk you through the process of permanently setting your $PATH, so you can breeze through your terminal sessions without having to set it again and again. Let's dive in! 💪🔥

The Problem 😫

As mentioned in the context, the issue at hand is that the changes made to the $PATH variable using the export command are not persistent across different terminal sessions. Every time you exit the terminal, the updated $PATH is lost, causing inconvenience and wasted time.

The Solution ✨

To permanently set your $PATH on Linux/Unix, you need to modify a configuration file that is read during startup. The specific file to edit depends on the distribution you are using. Let's explore these options:

For Ubuntu and Debian-based Distributions 🐧

  1. Open a terminal.

  2. In the terminal, enter the following command to edit the .bashrc file using a text editor (such as nano or vim):

nano ~/.bashrc
  1. Scroll to the end of the file and find the line that starts with export PATH=.

  2. Add your desired directory to the $PATH. For example, if you want to add the directory /path/to/dir, add the following line:

export PATH="$PATH:/path/to/dir"
  1. Save the file by pressing Ctrl + X, then Y, and finally Enter to confirm the filename.

For Red Hat-based Distributions (e.g., CentOS, Fedora) 🎩

  1. Open a terminal.

  2. In the terminal, enter the following command to edit the .bash_profile file:

nano ~/.bash_profile
  1. Scroll to the end of the file and find the line that starts with export PATH=.

  2. Add your desired directory to the $PATH, following the same format as described in the previous example.

  3. Save the file using the same steps as mentioned earlier.

For other Linux/Unix Distributions 🐧

  1. Open a terminal.

  2. In the terminal, enter the following command to edit the .bash_profile or .bashrc file (depending on the distribution):

nano ~/.bash_profile

or

nano ~/.bashrc
  1. Similar to the previous steps, find the line that starts with export PATH= and append your desired directory.

  2. Save the file as mentioned before.

Verifying the Changes ✅

To ensure that the changes to your $PATH are in effect, you can either open a new terminal session or run the following command in your current terminal:

source ~/.bashrc

or

source ~/.bash_profile

This command reloads the configuration file, and you should now see the updated $PATH when you run echo $PATH.

📣 Take Action and Enjoy the Permanence!

Congratulations! You have successfully learned how to permanently set your $PATH on Linux/Unix. No more frustrations with lost $PATH settings! Now you can focus on your work or projects without worrying about resetting your $PATH every time you start a new session.

If you found this guide helpful, feel free to share it with your fellow Linux users. And remember, never stop exploring the vast possibilities of the Linux command line! Happy coding! 🎉🚀

Share your favorite tip or trick for mastering the Linux command line in the comments below! Let's learn from each other! 💡💬


More Stories

Cover Image for How can I echo a newline in a batch file?

How can I echo a newline in a batch file?

updated a few hours ago
batch-filenewlinewindows

🔥 💻 🆒 Title: "Getting a Fresh Start: How to Echo a Newline in a Batch File" Introduction: Hey there, tech enthusiasts! Have you ever found yourself in a sticky situation with your batch file output? We've got your back! In this exciting blog post, we

Matheus Mello
Matheus Mello
Cover Image for How do I run Redis on Windows?

How do I run Redis on Windows?

updated a few hours ago
rediswindows

# Running Redis on Windows: Easy Solutions for Redis Enthusiasts! 🚀 Redis is a powerful and popular in-memory data structure store that offers blazing-fast performance and versatility. However, if you're a Windows user, you might have stumbled upon the c

Matheus Mello
Matheus Mello
Cover Image for Best way to strip punctuation from a string

Best way to strip punctuation from a string

updated a few hours ago
punctuationpythonstring

# The Art of Stripping Punctuation: Simplifying Your Strings 💥✂️ Are you tired of dealing with pesky punctuation marks that cause chaos in your strings? Have no fear, for we have a solution that will strip those buggers away and leave your texts clean an

Matheus Mello
Matheus Mello
Cover Image for Purge or recreate a Ruby on Rails database

Purge or recreate a Ruby on Rails database

updated a few hours ago
rakeruby-on-railsruby-on-rails-3

# Purge or Recreate a Ruby on Rails Database: A Simple Guide 🚀 So, you have a Ruby on Rails database that's full of data, and you're now considering deleting everything and starting from scratch. Should you purge the database or recreate it? 🤔 Well, my

Matheus Mello
Matheus Mello