Set Environment Variable in PowerShell for Mac


If you want to set an Environment Variable in PowerShell for Mac, you can make use of the $env automatic variable or by making use of the Set-Item cmdlet.

Let's take a look at both ways with an example each.


Example 1: Set Environment Variable Using $env automatic variable

    $env:SERVER_NAME = "Production"
    PowerShell - Set Environment Variable Using $env automatic variable

Example 2: Set Environment Variable Using Set-Item cmdlet

    PS /> SET-Item -Path Env:VERSION -Value "3.5" 
    
    PS /> GET-Item Env:VERSION                     
    
    Name                           Value
    ----                           -----
    VERSION                        3.5
    
    PowerShell - Set Environment Variable Using Set-Item cmdlet

Facing issues? Have Questions? Post them here! I am happy to answer!

Author Info:

Rakesh (He/Him) has over 14+ years of experience in Web and Application development. He is the author of insightful How-To articles for Code2care.

Follow him on: X

You can also reach out to him via e-mail: rakesh@code2care.org

Copyright © Code2care 2024 | Privacy Policy | About Us | Contact Us | Sitemap