How to make dotnet globally accessible in windows powershell?

Viewed 3377

I've installed .NET Core SDK on Windows 10 machine using dotnet-install scripts with the powershell command

./dotnet-install.ps1 -Channel Current

SDK was installed to default location C:\Users\[USERNAME]\AppData\Local\Microsoft\dotnet and the only way I can use it from another location is

C:\Users\[USERNAME]\AppData\Local\Microsoft\dotnet\dotnet.exe

How to make it global to use just dotnet anywhere?

3 Answers

When you install it via scripts use key -InstallDir for change directory. To use exe file from everywhere just change Environment variable (add path to exe). For add it to your user PS profile:

Add-Content -Path $Profile.CurrentUserAllHosts -Value '$Env:Path += ";C:\Users\[USERNAME]\AppData\Local\Microsoft\dotnet\dotnet.exe"'

To make dotnet globally, then you have to add directory where dotnet.exe is present to PATH environment variable.

Please keep in mind that default -InstallDir is %LocalAppData%\Microsoft\dotnet, so it is located under user folder, and it would be not available for all users on the machine. To make a dotnet fully globally you should install it to directory which would be accessible for all users on given machine.

The link by Vad helped. In my case, the dotnet folder was present in both locations aka C:\Program Files (x86)\dotnet and C:\Program Files\dotnet.
So by pressing Windows Key and typing env to select Edit the system environment variables, then moving x64 aka Program Files path up in GUI solved my problem:

enter image description here

Then checked by opening a new command prompt:

enter image description here

Related