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!
- How to load zsh profile on opening shell terminal
- Set Python 3.8 as a default python version on macOS
- Show CPU and Memory Usage on macOS Menu Bar
- How to save macOS Terminal outputs as text file
- How to install wget on macOS
- Display ls command file sizes in KB (kilobytes) MB (megabytes) or GB (gigabytes) [Linux/macOS]
- How to Change Mouse Wheel Scroll Direction on Mac
- macOS R installation steps
- How to open terminal on Mac to run commands
- How to know your Mac Screen Resolution?
- Safari - Get HTTP Request Response Headers
- Opening mac Terminal
- bash: command not found error [macOS Terminal Linux, Unix or Windows]
- Add Bookmark macOS Safari
- How to check RAM details on Mac?
- How to install Java on macOS [Big Sur]
- How to Display Analog Clock on Mac Menu Bar
- How to remove app from Dock when closed [macOS Big Sur]
- How to add to PATH in macOS Big Sur
- Keyboard Shortcut to delete a file on a Mac [Macbook]
- How to increase macOS Terminal text font size (Big Sur)
- Permanently set $PATH variable in Mac Zsh shell
- Delete a Directory using Mac Terminal Command
- Remove Now Playing icon from macOS Big Sur Menu Bar
- How to find files taking up space on your Mac
- reCAPTCHA Implementation Tutorial - CSS
- AADSTS90033: A transient error has occurred. Please try again. [Microsoft 365] - Microsoft
- Increase Android Emulator Timeout time - Android
- How to remove Floating Action Button Android Studio Blank Activity Template - Android-Studio
- Top 3 Awesome Text Editors developers prefer at workplace - Sublime