Set Environment Variables in Mac OS

Set Environment Variables in Mac OS

If you want to set an environment variable in your Mac OS system then for this you have to use the export variable_name=value command. And if the value contains spaces then the value must be enclosed in double quotes; In this tutorial, we will show you how to set environment variables in Mac OS using the zsh variable_name command on the terminal.

How to Set Environment Variables in Mac Os using ZSH Terminal

Here are some steps to set environment variables in Mac using zsh command on 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

AuthorAdmin

Greetings, I'm Devendra Dode, a full-stack developer, entrepreneur, and the proud owner of Tutsmake.com. My passion lies in crafting informative tutorials and offering valuable tips to assist fellow developers on their coding journey. Within my content, I cover a spectrum of technologies, including PHP, Python, JavaScript, jQuery, Laravel, Livewire, CodeIgniter, Node.js, Express.js, Vue.js, Angular.js, React.js, MySQL, MongoDB, REST APIs, Windows, XAMPP, Linux, Ubuntu, Amazon AWS, Composer, SEO, WordPress, SSL, and Bootstrap. Whether you're starting out or looking for advanced examples, I provide step-by-step guides and practical demonstrations to make your learning experience seamless. Let's explore the diverse realms of coding together.

Leave a Reply

Your email address will not be published. Required fields are marked *