powershell下设置全局环境变量
程序员文章站
2023-12-30 18:14:16
...
以JDK为例
[environment]::SetEnvironmentvariable("JAVA_HOME","C:\Program Files\jdk-13.0.2",[System.EnvironmentVariableTarget]::Machine)
[environment]::SetEnvironmentvariable("CLASSPATH",".;%JAVA_HOME%\lib",[System.EnvironmentVariableTarget]::Machine)
[environment]::SetEnvironmentvariable("Path","C:\Windows\system32;C:\Windows;C:\Windows\System32\Wbem;C:\Windows\System32\WindowsPowerShell\v1.0\;C:\Windows\System32\OpenSSH\;C:\Users\Administrator\AppData\Local\Microsoft\WindowsApps;%JAVA_HOME%\bin;",[System.EnvironmentVariableTarget]::Machine)
示例
[environment]::SetEnvironmentvariable("CATALINA_HOME","C:\Program Files\apache-tomcat-9.0.31",[System.EnvironmentVariableTarget]::Machine)
[environment]::SetEnvironmentvariable("MARIADB_HOME","C:\Program Files\MariaDB 10.5",[System.EnvironmentVariableTarget]::Machine)
[environment]::SetEnvironmentvariable("JAVA_HOME","C:\Program Files\jdk-13.0.2",[System.EnvironmentVariableTarget]::Machine)
[environment]::SetEnvironmentvariable("CLASSPATH",".;C:\Program Files\jdk-13.0.2\lib",[System.EnvironmentVariableTarget]::Machine)
[environment]::SetEnvironmentvariable("Path","C:\Program Files\Python38\Scripts\;C:\Program Files\Python38\;C:\Windows\system32;C:\Windows;C:\Windows\System32\Wbem;C:\Windows\System32\WindowsPowerShell\v1.0\;C:\Windows\System32\OpenSSH\;C:\Users\Administrator\AppData\Local\Microsoft\WindowsApps;C:\Program Files\jdk-13.0.2\bin;C:\Program Files\MariaDB 10.5\bin;",[System.EnvironmentVariableTarget]::Machine)