chocolatey / choco

Chocolatey - the package manager for Windows
https://chocolatey.org
Other
10.11k stars 892 forks source link

Helper functions not recognized after install #1797

Open E3V3A opened 5 years ago

E3V3A commented 5 years ago

I just installed choco using PWSH 6.1.1 on W8.1.

After suspicious install messages (shown below) I was looking to use some of the helper functions, such as the alias refreshenv and Update-SessionEnvironment. As suggested I also included the suggested lines in $profile.

What You Are Seeing?

Powershell doesn't recognize Update-SessionEnvironment, only RefreshEnv.cmd, but normal choco.exe works, since it's in the path.

What is Expected?

To be able to use: refreshenv and Update-SessionEnvironment etc, from PS.

Output Log

My install log:

$ Get-MyPolicy

        MachinePolicy   : Undefined
        UserPolicy      : Undefined
        Process         : Undefined
        CurrentUser     : Bypass
        LocalMachine    : AllSigned

$ Set-ExecutionPolicy Bypass -Scope Process -Force; iex ((New-Object System.Net.WebClient).DownloadString('https://chocolatey.org/install.ps1'))

Unable to set PowerShell to use TLS 1.2 and TLS 1.1 due to old .NET Framework installed. 
If you see underlying connection closed or trust errors, you may need to do one or more of the following: 
(1) upgrade to .NET Framework 4.5+ and PowerShell v3, 
(2) specify internal Chocolatey package location (set $env:chocolateyDownloadUrl prior to install or host the package internally), 
(3) use the Download + PowerShell method of install. 
See https://chocolatey.org/install for all install options.

Getting latest version of the Chocolatey package for download.
Exception calling "IsBypassed" with "1" argument(s): "Operation is not supported on this platform."
At line:130 char:15
+     } elseif (!$downloader.Proxy.IsBypassed($url)) {
+               ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo          : NotSpecified: (:) [], MethodInvocationException
+ FullyQualifiedErrorId : PlatformNotSupportedException

Getting Chocolatey from https://chocolatey.org/api/v2/package/chocolatey/0.10.13.
Exception calling "IsBypassed" with "1" argument(s): "Operation is not supported on this platform."
At line:130 char:15
+     } elseif (!$downloader.Proxy.IsBypassed($url)) {
+               ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo          : NotSpecified: (:) [], MethodInvocationException
+ FullyQualifiedErrorId : PlatformNotSupportedException

Downloading 7-Zip commandline tool prior to extraction.
Exception calling "IsBypassed" with "1" argument(s): "Operation is not supported on this platform."
At line:130 char:15
+     } elseif (!$downloader.Proxy.IsBypassed($url)) {
+               ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo          : NotSpecified: (:) [], MethodInvocationException
+ FullyQualifiedErrorId : PlatformNotSupportedException

Extracting C:\Users\xxxx\AppData\Local\Temp\chocolatey\chocInstall\chocolatey.zip to C:\Users\xxxx\AppData\Local\Temp\chocolatey\chocInstall...
Installing chocolatey on this machine
Creating ChocolateyInstall as an environment variable (targeting 'Machine')
  Setting ChocolateyInstall to 'C:\ProgramData\chocolatey'

WARNING: It's very likely you will need to close and reopen your shell before you can use choco.
WARNING: Not able to set permissions for C:\ProgramData\chocolatey.

We are setting up the Chocolatey package repository.
The packages themselves go to 'C:\ProgramData\chocolatey\lib'
  (i.e. C:\ProgramData\chocolatey\lib\yourPackageName).
A shim file for the command line goes to 'C:\ProgramData\chocolatey\bin'
  and points to an executable in 'C:\ProgramData\chocolatey\lib\yourPackageName'.

Creating Chocolatey folders if they do not already exist.

WARNING: You can safely ignore errors related to missing log files when
  upgrading from a version of Chocolatey less than 0.9.9.
  'Batch file could not be found' is also safe to ignore.
  'The system cannot find the file specified' - also safe.
chocolatey.nupkg file not installed in lib.
 Attempting to locate it from bootstrapper.
PATH environment variable does not have C:\ProgramData\chocolatey\bin in it. Adding...
Adding Chocolatey to the profile. This will provide tab completion, refreshenv, etc.

WARNING: Unable to add Chocolatey to the profile. You will need to do it manually. 
Error was 'Cannot bind parameter 'Encoding'. Cannot convert the "byte" value of type "System.String" to type "System.Text.Encoding".'

This is how add the Chocolatey Profile manually.
Find your $profile. Then add the following lines to it:

$ChocolateyProfile = "$env:ChocolateyInstall\helpers\chocolateyProfile.psm1"
if (Test-Path($ChocolateyProfile)) {
  Import-Module "$ChocolateyProfile"
}

Chocolatey (choco.exe) is now ready.

You can call choco from anywhere, command line or powershell by typing choco.
Run choco /? for a list of functions.
You may need to shut down and restart powershell and/or consoles
 first prior to using choco.
Ensuring chocolatey commands are on the path
Ensuring chocolatey.nupkg is in the lib folder
pauby commented 5 years ago

@E3V3A You'll get mixed results using PowerShell Core and installing Chocolatey. Use Windows PowerShell to do so as Core is not supported at present.

Note the errors in the logs above (as you will need to act on then) and also note that they indicate that Chocolatey has not installed completely.

E3V3A commented 5 years ago

Aha. Can I just repeat the install on top, or do I need to remove something? (I already installed a bunch of stuff, that seem to work. Will they disappear?)

BTW. What is the correct permissions for ProgramData/chocolatey?

PS. I also have the latest .NET...

E3V3A commented 5 years ago

Ok, re-installed using PS 5.1. Now it works as expected, although some of my previous profile items no longer work. (I suspect they interfere with Chocolatey?) Either way, this should be made more clear from the instructions page. I guess PWSH (Core) is the future and will be part of W10, if not already.

That said, does the bugs shown above give you any ideas? Since most of choco worked already, my guess is that the bugs shown are of the simple kind, that may be easily fixed?

E3V3A commented 5 years ago

Now it works also in pwsh :+1:

Install bug still need to be fixed.

ferventcoder commented 5 years ago

I am pretty sure we mention it at least somewhere that PowerShell core doesn't work. I don't see it on the Install page though under requirements, so let's fix that. Done at https://github.com/chocolatey/choco-wiki/commit/d5126fce9d7abd5d08aefe7d69fe6dd394941ad8.

BTW. What is the correct permissions for ProgramData/chocolatey?

C:\ > cacls.exe C:\ProgramData\chocolatey
C:\ProgramData\chocolatey NT AUTHORITY\SYSTEM:(OI)(CI)F
                          BUILTIN\Administrators:(OI)(CI)F
                          BUILTIN\Users:(OI)(CI)R
ferventcoder commented 5 years ago

Aha. Can I just repeat the install on top, or do I need to remove something? (I already installed a bunch of stuff, that seem to work. Will they disappear?)

Maybe?

E3V3A commented 5 years ago

I have the same cacls as you, so all good there.

Will they disappear?

No, so far I see nothing missing.

ferventcoder commented 5 years ago

For profile, you will want refreshenv (no .cmd afterwards, that only works with cmd.exe) to work. You just need to add the powershell profile, which it sounds like you might have already started on.

https://chocolatey.org/docs/troubleshooting#why-does-choco-intab-not-work-for-me

E3V3A commented 5 years ago

I'm not using cmd.exe, and it works in both PS5 and pwsh (Core), after you have added the choco script loading lines in both your profile directories.

ferventcoder commented 5 years ago

If Chocolatey itself appears to be somewhat working in powershell core, it's likely because under the covers you still have PowerShell 5.1 installed on the system and Chocolatey runs its own PowerShell host (using PowerShell 5.1). pwsh.exe is simply calling choco to run like any command shell would.

So to get to PowerShell 6+ (Core) support, we need to start looking at adjustments to what is not available in that area and account for them in some ways. The proxy bypass not being available is kind of interesting, but I'm guessing that is based on what's in .NET Core and PowerShell Core by proxy (ha, that was not intentional).

E3V3A commented 5 years ago

Sound great. Thanks for the support. :1st_place_medal:

argumemnon commented 4 years ago

Commenting here as I too had this issue installing with PS Core 6.2.3. Was Chocolately updated recently to support Core versions? I do not see the change you made here https://github.com/chocolatey/choco-wiki/commit/d5126fce9d7abd5d08aefe7d69fe6dd394941ad8 reflected on your live site (https://chocolatey.org/install) / (https://github.com/chocolatey/chocolatey.org/blob/master/chocolatey/Website/Views/Pages/Install.cshtml)

AdmiringWorm commented 4 years ago

@argumemnon no, support for PS Core has not been added to chocolatey yet (AFAIK). The documentation the commit you link to is not the install page though, but rather from the full docs page here: https://chocolatey.org/docs.