Permanently set $PATH variable in Mac Zsh shell


You must have noticed that as soon as you exit your Mac Terminal, the environment variable such as $PATH is not available. The $PATH was available until the Terminal session was active, but soon as it was terminated, we do not have access to the variable. In order to set the $PATH variable permanently, you would need to set it in the .zshrc file (Z-Shell resource file).

What is .zshrc file?

.zshrc is a Zsh shell resource file. This file runs whenever you start zsh shell. So all the commands and scripts you write in this file are executed as soon as you launch the terminal. So if you want to set paths and other variables that you need for day-to-day programming or executions, it's always better to add them to this file.

How to add $PATH in .zshrc file?

  1. Open Terminal,
  2. Make sure you are on Zsh Shell, if not type zsh and hit enter,
  3. Now type nano ~/.zshrc
  4. Now add your $PATH variable details: Example: export PATH="$PATH:/opt/homebrew/bin/"
  5. Press Control + X, followed by Y to save the file, press enter to exit Nano,
  6. Now type command source ~/.zshrc to apply changes.
Permanenlty set PATH variable in Mac Zsh Shell
Permanenlty set PATH variable in Mac Zsh Shell

Now even when you close your terminal and open it or switch between prompts, the Zsh shell will always have your $PATH variable set and it will not get lost.



Have Questions? Post them here!





Hello there!,

You are using AdBlocker!

I am an independent developer trying to help fellow developers and students to resolve issues faced on a day-to-day basis, we 'Code to Care' . There is a lot of expenses involved in hosting and managing a website that's the reason we have ads.

A humble request to you to disable adBlocker on Code2care.org and support us pay our bills.

Thanks,
Cod2care - Line's of code for change.

To see contents reload page after unblocking
Code2care is an initiative to publish and share varied knowledge in programming and technical areas gathered during day-to-day learnings and development activities. Students and Software Developers can leverage this portal to find solutions to their various queries without re-inventing the wheel by referring to our easy to understand posts. Technical posts might include Learnings, Video Tutorials, Code Snippets, Tips-n-tricks, How Tos, Blogs, Articles, etc. on various platforms like Windows, Mac, Linux, Mobile platforms, etc. Technologies/Languages like Java, Objective-C, PHP, .Net, Android, SharePoint, jQuery, HTML, CSS, etc.