- This topic has 5 replies, 4 voices, and was last updated 11 hours, 5 minutes ago by
June 30, 2020 at 3:32 pm #239288
Does anyone know if
[Environment]::SetEnvironmentVariableis it a valid way to permanently set environment variables in PS 7.0.2 on MacOS?
From my testing, it doesn’t appear to be a permanent operation. Is it the case that the only way to achieve this on MacOS is by adding it to your PSProfile? I’ve run into some blog posts that mention there might be a json document somewhere with these preferences.
How are others doing it?
- This topic was modified 1 week, 1 day ago by Phatmandrake.
July 3, 2020 at 3:55 pm #240110Senior ModeratorTopics: 9Replies: 1236Points: 4,443Rank: Community Hero
July 8, 2020 at 9:54 am #241043
Thanks for sharing that. I am unable to locate that file so perhaps there is another source that is modifying $ENV:Path. Does anyone know how $PSProfile, this config file, and the existing ENV variables from MacOS Terminal interact? Trying to come up with the most stable way to modify $ENV:Path cross-platform for a module.
July 8, 2020 at 1:16 pm #241124ParticipantTopics: 10Replies: 120Points: 665Rank: Major Contributor
Trying to come up with the most stable way to modify $ENV:Path cross-platform for a module.
If I understand you’re objective correctly, I would only modify
$ENV:PATHtemporarily when loading the module and here’s why:
- The change to
$ENV:PATHships with the module
- You don’t have to necessarily depend on editing
$PSProfileor configuration files on any target systems (and knowing Microsoft, the path or file name may change at some point)
- Avoid a permanent change to paths when only one module may require it
- Always best to leave PowerShell out-of-box config untouched for the most part
In short, I would:
- Module .psm1 if only (this) module requires it (best for shipping to other systems); or
$PSProfileto be available without having to load the module
- Import module in
I’ve accomplished something similar but for aliases to commands I’ve written that allow me to control lighting and timers from macOS Terminal.
- The change to
July 8, 2020 at 7:58 pm #241190
Thank You for responding! The module depends on a Binary. It’s actually this one: https://github.com/GoogleCloudPlatform/google-cloud-powershell it’s unfortunately not being curated, and there’s an issue where the Module is unable to see the gcloud python binary that it uses to bootstrap the PS Module. It’s using a Windows only method for updating the path. It would make sense for this use case that gcloud is made available in the $env:PATH.
Now there are ways of updating this to not need the gcloud binary entirely, but to get this thing up and running now I wanted to make an easy to edit suggestion.
July 8, 2020 at 9:00 pm #241199ParticipantTopics: 0Replies: 5Points: 22Rank: Member
When I am programming my modules for cross platform I have done specific checks for IsMacOs or IsLinux and then changed the paths that way. I also use now PSFramework where I can store them in a central config and recall them from there which makes life easier.
For mac you can open the Terminal and run the command
printenv.For displaying the value of any specific environment variable run the
echo $[variable name].You can set a temporary variable by opening the terminal and running
exportcommand followed by the variable name and its value: Daves-MacBook-Pro:~ DaveG$ export GITHUB_HOME=/Library/GitHub/.
Mac uses bash shell. The environment variables can be added to the
.bash_profiledirectory, for the current user. The path to this file can be found using the command: Daves-MacBook-Pro:~ DaveG$ ~/.bash_profile.
Just use a text editor to edit the file and if no file exists then you can create a new file called
.bash_profile.Edit the file and add your desired environment variables using
exportcommand. Save it and restart terminal and you should be good to go.
- This reply was modified 11 hours, 4 minutes ago by Dave G.
- You must be logged in to reply to this topic.