[ad_1]
To set environment variables in Mac OS; In this tutorial, you will learn how to set environment variables in mac os using zsh terminal.
![]()
How to Set PHP Environment Variables Ubuntu
Steps to set environment variables in mac os using zsh terminal:
- Step 1: Start Terminal

- Step 2: Specify the Shell
- Step 3: Edit Shell Profile File
- Step 4: Set/Add Environment Variables Mac
- Step 5: Reload Profile
- Step 6: Verify the Environment Variable
Step 1: Start Terminal
Firstly, Press Cmd + Space to open Spotlight Search and Type “Terminal” or “Terminal.app” into the search bar.
Step 2: Specify the Shell
Now, you need to run the following command on terminal to can check your current shell:
![]()
echo $SHELL
Step 3: Edit Shell Profile File
Two common shell profile files are .bash_profile (for Bash) and .zshrc (for Zsh). you can use nano or vi text editor to edit the file. For example, if you are using Bash, you can run:
nano ~/.bash_profile
For Zsh shell:
![]()
nano ~/.zshrc
Step 4: Set/Add Environment Variables Mac
Add your environment variables in the format export VARIABLE_NAME="variable_value". For example, to set a database connection variable:
export YOUR_VARIABLE_NAME="Your Variable Value"
In Nano, you can save your changes by pressing Ctrl + O, then press Enter. To exit, press Ctrl + X.
Step 5: Reload Profile
For the changes to take effect, you can either restart your terminal and execute the following command:
source ~/.bash_profile
Step 6: Verify the Environment Variable
Now, you need to run the following commands on the terminal to verify that the environment variable is set:
echo $MY_VARIABLE
Conclusion
That’s it! You’ve successfully set and accessed environment variables in mac os using terminal zsh.
Recommended Tutorials
[ad_2]
