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?
- Open Terminal,
- Make sure you are on Zsh Shell, if not type zsh and hit enter,
- Now type nano ~/.zshrc
- Now add your $PATH variable details: Example: export PATH="$PATH:/opt/homebrew/bin/"
- Press Control + X, followed by Y to save the file, press enter to exit Nano,
- Now type command source ~/.zshrc to apply changes.
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!
- Open New Terminal Window Using Keyboard Shortcut macOS
- How to Refresh Mac Desktop
- How to remove app from Dock when closed [macOS Big Sur]
- WARNING: Python 2.7 is not recommended [macOS Big Sur]
- Terminal Command to get the list of available shells in macOS
- Add Bookmark macOS Safari
- Youtube spacebar not working in search on macOS Safari
- How to refresh Safari on Mac (macOS) using keyboard shortcut
- How to know your Mac Screen Resolution?
- Disable Startup Sound on macOS
- bash: command not found error [macOS Terminal Linux, Unix or Windows]
- Test internet speed using macOS Terminal command
- How to hide or display Wifi icon in macOS Bug Sur Menu Bar
- Limit scrollback rows in macOS Terminal
- [macOS] Change homepage Macbook Safari Browser
- wget Command on macOS Terminal
- How to install Java on macOS [Big Sur]
- How to increase macOS Terminal text font size (Big Sur)
- How to check zsh installed version using terminal
- This operation couldnt be completed. Unable to locate a Java Runtime. [macOS]
- ls: .: Operation not permitted - Mac Big Sur Terminal Zsh Error
- How to install maven in macOS using Terminal Command
- How to open new tabs macOS Terminal
- How to uninstall GarageBand from Mac
- How to Restart Mac using Terminal Command
- Take Screenshots on Mac OS without Keyboard - Mac-OS-X
- Launch Notepad++ html document in any web browser - NotepadPlusPlus
- Fix SharePoint Error - The Managed Metadata Service or Connection is currently not available. The Application Pool or Managed Metadata Web Service may not have been started - SharePoint
- How to recover SharePoint FARM if the SQL Server IP changes - SharePoint
- How to add Date and Time to Windows Notepad File - NotepadPlusPlus