[英]Set the PSModulePath variable on Linux - PowerShell 7
I am trying to update the PSModulePath variable on Linux (CentOS 7.9).我正在尝试更新 Linux (CentOS 7.9) 上的 PSModulePath 变量。 I have tried:
我试过了:
# Check current path(s)
$env:PSModulePath
/opt/microsoft/powershell/7-lts/Modules
# Update the variable
$env:PSModulePath += ":/opt/MyModules"
# Confirm the update
$env:PSModulePath
/opt/microsoft/powershell/7-lts/Modules:/opt/MyModules
All working OK.一切正常。 Now I try to relaunch PowerShell:
现在我尝试重新启动 PowerShell:
exit
pwsh
$env:PSModulePath
/opt/microsoft/powershell/7-lts/Modules
The setting does not persist.该设置不会保留。 How can I fix this?
我怎样才能解决这个问题?
Using: PowerShell 7使用:PowerShell 7
Linux CentOS 7.9 Linux CentOS 7.9
Assigning to $env:PSModulePath
sets the process -scoped copy of the PSModulePath
environment variable, which is by definition not persisted;分配给
$env:PSModulePath
设置PSModulePath
环境变量的process -scoped 副本,根据定义,它是不持久的; it disappears when the process terminates.它在进程终止时消失。
To make persistent changes, you have two options:要进行持久更改,您有两种选择:
Use your system's features for defining persistent environment variables.使用系统的功能来定义持久环境变量。
Add the modification statement to your PowerShell $PROFILE
file (there are multiple profiles, based on whether they apply to all vs. the current user, and all vs. specific PowerShell host environments).将修改语句添加到您的 PowerShell
$PROFILE
文件(有多个配置文件,基于它们是否适用于所有与当前用户,以及所有与特定 PowerShell 主机环境)。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.