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
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:
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:
For Zsh shell:
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:
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:
That’s it! You’ve successfully set and accessed environment variables in mac os using terminal zsh.