I am trying to update the PSModulePath variable on Linux (CentOS 7.9). 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:
exit
pwsh
$env:PSModulePath
/opt/microsoft/powershell/7-lts/Modules
The setting does not persist. How can I fix this?
Using: PowerShell 7
Linux CentOS 7.9
CodePudding user response:
Assigning to $env:PSModulePath
sets the process-scoped copy of the PSModulePath
environment variable, which is by definition not persisted; it disappears when the process terminates.
To make persistent changes, you have two options:
Use your system's features for defining persistent environment variables.
- For instance, for Ubuntu see this askubuntu.com answer.
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).