Developers mostly understand the meaning behind environment variable. The case you are here, you probably understand what an environment variable is. However, sometimes for running certain softwares and eliminating a few errors require changing an environment variable. Therefore, this article tells you ways to set environment variable in macOS Catalina.
What is an Environment Variable?
Environment variable is simply a variable with a stored value in operating system. It has a name and a stored value. There are different types of the environment variables, for example, variables storing path to certain libraries or local system settings. An environment variable can also store current working directory or default shell.
Method to set environment variable in macOS Catalina:
In order to set environment variable, we only need one application. Terminal is the utility which we are going to use. First of all, let’s enlist the already available environment variables. Use the following command in terminal:
If you want to view the value of a variable then use the following command:
Replace the name_of_variable with the variable of which you want to see the value. For example, echo $HOME would return the value of your home path.
Set permanent environment variable in macOS Catalina
Now, you know the environment variables in use. Also you know the method to read the value of those variables. Let’s learn how to change value of an environment variable permanently in Catalina. If you echo the value of Shell in Catalina, you’d see that you are using ZSH instead of Bash as compared with the previous versions of macOS. Use the following command to edit the zshenv configuration.
Using the following syntax, add the custom value of any environment variable in the file. For example, I am adding HOME variable value like below:
After writing your variable value change command using the syntax shown above; press CTRL+X and press Y to save the file.
Run echo command to be sure about the updated value of the environment variable. This was the method to permanently change the value of any environment variable in Catalina.
Set temporary environment variable in macOS Catalina
If you don’t want to set a permanent value of the environment variable in your macOS Catalina, then there is another method. You need to use the following command in the terminal to change the value of any variable. Here I am changing the value of $HOME variable temporarily.
The colon sign appends the new value of the variable which is defined after the equals to sign.
This is how you can set a non-persistent or persistent environment variable in Mac OS Catalina. On the contrary, if you want to do the same in Linux then read: How to set environment variables in Linux. Surprisingly, the executable commands are the same.