MATLAB Answers

How do I set add or change environment variables?

345 views (last 30 days)
In the process of troubleshooting MATLAB, I have been asked to change the environment variables on my machine.  How can I set or change the environment variables?

Accepted Answer

MathWorks Support Team
MathWorks Support Team on 7 Nov 2016
Below are instructions for setting environment variables for various platforms.
== Windows ==
Open the* Environment Variables* dialog by following these two steps:
1) From Start *-> *Run,  execute the following CPL command "sysdm.cpl", this will open the System Properties dialog
2) Click on the Advanced tab, click on the "Environment Variables..."  button, this will open the Environment Variables dialog
You can now create/edit both "System variables" as well as "User variables"; the system variables will be shared for all users, while user variables affect only your account/profile.
   
== Mac/Linux OS ==
There are multiple ways to set environment variables depending on the type of shell you are using.  To determine the your shell type, use the "echo" command to see the value of the "SHELL" environment variable:
 
echo $SHELL
For a tcsh or csh shell, use the following syntax:
 
setenv <name> <value>
for example:
 
setenv JAVA_HOME /usr/local/
For a bash shell use the following syntax:
 
export <name>=<value>
for example:
 
export JAVA_HOME=/usr/local/
Note that the environment variable has only effect on that particular instance of that shell.  If you try to open a new shell or start a program outside your original shell the environment variable you created will not have an effect.
 

More Answers (0)

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!