Skip to content
This repository has been archived by the owner on Feb 19, 2019. It is now read-only.

Chocolatey install did not configure $env:Path #140

Closed
dotnetchris opened this issue Aug 22, 2012 · 16 comments
Closed

Chocolatey install did not configure $env:Path #140

dotnetchris opened this issue Aug 22, 2012 · 16 comments

Comments

@dotnetchris
Copy link

After installing Chocolatey by executing the @PowerShell.... command on the chocolatey.org homepage, my environment path was not updated.

After the install:

C:\projects> Get-Command chocolatey
Get-Command : The term 'chocolatey' is not recognized as the name of a cmdlet, function, script file, or operable program. Check the spelling of the name, or if
a path was included, verify that the path is correct and try again.

With my hacking:

C:\projects> $env:Path += ";C:\Chocolatey\bin;"

C:\projects> Get-Command chocolatey

CommandType Name Definition
Application chocolatey.bat C:\Chocolatey\bin\chocolatey.bat

Windows 7 Pro x64
Powershell policy unrestricted
UAC disabled

@ferventcoder
Copy link
Contributor

This only happens on the session (or existing sessions) that you do the install from, correct?

@ferventcoder
Copy link
Contributor

Once you close and open a new powershell session, this works appropriately, correct?

@ferventcoder
Copy link
Contributor

Or you actually checked the environment path and it wasn't there and then added that to your session?

@dotnetchris
Copy link
Author

@ferventcoder the environment variable for chocolatey was not there, i had to manually add it with

C:\projects> $env:Path += ";C:\Chocolatey\bin;"

@ferventcoder
Copy link
Contributor

Last time I checked that only updates your current session, not the path variables stored on your machine.

@dotnetchris
Copy link
Author

@ferventcoder are you refering to the chocolatey install or env:Path? env:Path is most certainly system Environment Path variable, i also used this same command to setup environment path for python after it didn't do it either.

@ferventcoder
Copy link
Contributor

I'm referring to opening control panel, system, advanced, variables and the PATH variables in there. There is one for user and one for system. Just b/c it doesn't end up in your current session (of powershell or cmd) doesn't mean it didn't get added to the actual path.

Here's an experiment: open the system stuff in control panel and then go back to your powershell session and add c:\bob; to the path the same way you did in powershell. Now look in the actual path to see if it got added. Both places (user and system). Now close and reopen powershell. Write-host your path. Is c:\bob still there?

@Iristyle
Copy link
Contributor

The problem here is that Powershell does not "recapture" the environment variables once a session has been started.

So PATH could be modified, after running an installer, but Chocolatey cannot gain access to these without using the .NET System EnvironmentVariable APIs or manually accessing the real location in the registry -- i.e..

(Get-ItemProperty 'HKLM:\SYSTEM\CurrentControlSet\Control\Session Manager\Environment' -Name Path).Path

IMHO, what needs to be done is that the environment needs to be refreshed after a given installer wraps up.

I would do a pull req, but not sure if this is the best / only spot where an installer finishes up.

https://github.com/chocolatey/chocolatey/blob/master/src/helpers/functions/Install-ChocolateyPackage.ps1#L63

To recapture any changes made to PATH by external processes.

$Env:PATH = (@(,[Environment]::GetEnvironmentVariable('PATH', 'Machine') -s
plit ';') + @([Environment]::GetEnvironmentVariable('PATH', 'User') -split ';') | Select -Unique) -join ';'

BTW - I was just coming to submit this issue based on Yeoman install failing on a machine without Ruby or Node initially installed.

@ferventcoder
Copy link
Contributor

I think I like that better dropped into a new issue - your fix... please submit as an enhancement.

@ferventcoder
Copy link
Contributor

Just FYI - choco 0.9.10 supports this now without closing and reopening your shell - chocolatey/choco#664

@acgetchell
Copy link

acgetchell commented Aug 26, 2017

After running

choco install cmake.install --installargs 'ADD_CMAKE_TO_PATH=""System""'
refreshenv

I still have to close out the Admin PowerShell window before cmake is found.

Same thing happens with:

choco install git -y
refreshenv

@ferventcoder
Copy link
Contributor

ferventcoder commented Aug 27, 2017

@acgetchell Can you tell me the output of calling refreshenv? Does it say "Refreshing for cmd.exe" or does it say for powershell.exe? If it says the former, it means you do not have the PowerShell profile installed - which provides this and tab completion.

See https://chocolatey.org/docs/troubleshooting#why-does-choco-intab-not-work-for-me on how to remedy this so that when you call refreshenv, it is the PowerShell version that is being called and not refreshenv.bat.

@ferventcoder
Copy link
Contributor

Please see chocolatey/choco#991 and chocolatey/choco#894 to get a better understanding of why this isn't set by default on install.

@ferventcoder
Copy link
Contributor

I also filed chocolatey/choco#1392

@acgetchell
Copy link

acgetchell commented Aug 27, 2017

Works now. 👍 💯

screen shot 2017-08-27 at 11 19 20 am

@ferventcoder
Copy link
Contributor

@acgetchell Looks like an artifact of already having that in the PATH when you ran it the second time. It doesn't show that environment variables like PATH were updated in the output and I don't see a call to refreshenv here.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants