How do I set add or change environment variables?

364 次查看(过去 30 天)
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?

采纳的回答

MathWorks Support Team
编辑:MathWorks Support Team 2023-8-18
Below are instructions for setting environment variables on different Operating Systems.
Windows
Open the Environment Variables dialog by following these two steps:
1) In Windows Start Menu, type "env" then select "Edit the system environment variables"
2) Click the "Environment Variables..." button
You can create System Variables or User Variables using the "New..." button.
You can edit existing variables by selecting one from the list then click the "Edit..." button.
The system variables will be shared for all users, while user variables only affect your account/profile.
Linux/macOS
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 setting an environment variable using these methods on Linux or macOS will only affect the current Terminal session. If you try to open a new shell or start a program outside your original shell the environment variable will not apply.
  1 个评论
Walter Roberson
Walter Roberson 2023-1-15
The Windows sysdm.cpi that is discussed above makes permanent changes to the system.
For MacOS you should change a launchd plist https://apple.stackexchange.com/questions/289060/setting-variables-in-environment-plist and see https://stackoverflow.com/questions/135688/setting-environment-variables-on-os-x but be careful about which version the remarks there refer to (further down the page some people are specific about what is needed for which version.)

请先登录,再进行评论。

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Environment and Settings 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by