Setting up Environment Variables in Mac OS
For those who are looking for quick and easy video tutorial,
Jump right into this youtube video
otherwise, keep reading this article.
Pre-requisites
- knowledge about shell interpreter like bash
- know how to run commands in terminal
Note : This article demonstrates how to set environment variables with bash shell interpreter in terminal application that comes out of the box in MacOS.
1. Check the current environment variable settings.
you can list up by command “printenv” in the console.
if you want to check a specific environment variable, you can do check it with command “echo $variable_name”
2. Set an Environment Variable — temporary or permanent
you can set an environment variable for the temporary or permanent use. It depends on the case, if you need a variable for just one time, you can set it up using terminal. Otherwise, you can have it permanently in Bash Shell Startup Script with “Export” command.
- Temporary Setting
And then close the terminal window and open another one to check out if the set variable has disappeared or not.
2) Permanent Setting
For permanent setting, you need to understand where to put the “export” script. Here in this practice, you are going to edit “.bash_profile” file under your home directory.
Open the file with your preferred editor like
here “~/” path points to your home directory, don’t get confused about it.
For experiment, I am going to add a test directory to the PATH environment variable. Using “export” command, the PATH variable is going to hold the newly added directory.
Make sure to execute this to reload
In the end, I have successfully practiced permanent setting. This is going to be useful for any development environment setting hereafter.
Thanks!