Set Environment Variables in Mac OS


To set environment variables in Mac OS; In this tutorial, you will learn how to set environment variables in mac os using zsh terminal.

Ezoic

How to Set PHP Environment Variables Ubuntu

Steps to set environment variables in mac os using zsh terminal:

  • Step 1: Start TerminalEzoic
  • 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:

Ezoic

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:

Ezoic

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

Jaspreet Singh Ghuman

Jaspreet Singh Ghuman

Jassweb.com/

Passionate Professional Blogger, Freelancer, WordPress Enthusiast, Digital Marketer, Web Developer, Server Operator, Networking Expert. Empowering online presence with diverse skills.

jassweb logo

Jassweb always keeps its services up-to-date with the latest trends in the market, providing its customers all over the world with high-end and easily extensible internet, intranet, and extranet products.

Contact
San Vito Al Tagliamento 33078
Pordenone Italy
Item added to cart.
0 items - 0.00
Open chat
Scan the code
Hello 👋
Can we help you?