PowerShellGetv2
PowerShellGetv2 copied to clipboard
Can't install modules when running as non root user on Centos 7.6
Steps to reproduce
sudo -E -u NONROOTUSERNAME pwsh -Command "Install-Module -Name Az -AllowClobber -Scope CurrentUser -Force"
Expected behavior
Az module installed.
Actual behavior
NuGet provider is required to continue
This version of PowerShellGet requires minimum version '2.8.5.201' of NuGet provider to publish an item to NuGet-based repositories. The NuGet provider must be available in '' or ''. You can also install the
NuGet provider by running 'Install-PackageProvider -Name NuGet -MinimumVersion 2.8.5.201 -Force'. Do you want PowerShellGet to install and import the NuGet provider now?
[Y] Yes [N] No [S] Suspend [?] Help (default is "Y"): Y
PackageManagement\Install-PackageProvider : Unhandled Exception - Message:'The type initializer for 'Microsoft.PackageManagement.Internal.Utility.Extensions.FilesystemExtensions' threw an exception.' Name:'TypeInitializationException' Stack Trace:' at Microsoft.PackageManagement.Internal.Utility.Extensions.FilesystemExtensions.MakeSafeFileName(String input)
at Microsoft.PackageManagement.Internal.Utility.Plugin.DynamicType.DefineDynamicType(Type interfaceType)
at Microsoft.PackageManagement.Internal.Utility.Plugin.DynamicType..ctor(Type interfaceType, OrderedDictionary`2 methods, List`2 delegates, List`1 stubs)
at Microsoft.PackageManagement.Internal.Utility.Plugin.DynamicType.<>c__DisplayClass9_0.<Create>b__3()
at Microsoft.PackageManagement.Internal.Utility.Extensions.DictionaryExtensions.GetOrAdd[TKey,TValue](IDictionary`2 dictionary, TKey key, Func`1 valueFunction)
at Microsoft.PackageManagement.Internal.Utility.Plugin.DynamicType.Create(Type tInterface, OrderedDictionary`2 instanceMethods, List`2 delegateMethods, List`1 stubMethods, List`2 usedInstances)
at Microsoft.PackageManagement.Internal.Utility.Plugin.DynamicInterface.CreateProxy(Type tInterface, Object[] instances)
at Microsoft.PackageManagement.Internal.Utility.Plugin.DynamicInterface.DynamicCast(Type tInterface, Object[] instances)
at Microsoft.PackageManagement.Internal.Utility.Plugin.DynamicInterface.DynamicCast[TInterface](Object[] instances)
at Microsoft.PackageManagement.Internal.Utility.Plugin.DynamicInterfaceExtensions.As[TInterface](Object instance)
at Microsoft.PowerShell.PackageManagement.Cmdlets.CmdletBase.get_PackageManagementHost()
at Microsoft.PowerShell.PackageManagement.Cmdlets.CmdletBase.SelectProviders(String[] names)
at Microsoft.PowerShell.PackageManagement.Cmdlets.CmdletWithProvider.get_SelectedProviders()
at Microsoft.PowerShell.PackageManagement.Cmdlets.InstallPackageProvider.get_SelectedProviders()
at Microsoft.PowerShell.PackageManagement.Cmdlets.CmdletWithProvider.<get_CachedSelectedProviders>b__23_0()
at Microsoft.PackageManagement.Internal.Utility.Extensions.DictionaryExtensions.GetOrAdd[TKey,TValue](IDictionary`2 dictionary, TKey key, Func`1 valueFunction)
at Microsoft.PackageManagement.Internal.Utility.Extensions.Singleton`1.GetOrAdd(Func`1 newInstance, Object primaryKey, Object[] keys)
at Microsoft.PackageManagement.Internal.Utility.Extensions.SingletonExtensions.GetOrAdd[TResult](Object primaryKey, Func`1 newInstance, Object[] keys)
at Microsoft.PowerShell.PackageManagement.Cmdlets.CmdletWithProvider.get_CachedSelectedProviders()
at Microsoft.PowerShell.PackageManagement.Cmdlets.CmdletWithProvider.GenerateDynamicParameters()
at Microsoft.PowerShell.PackageManagement.Cmdlets.AsyncCmdlet.<>c__DisplayClass83_0.<AsyncRun>b__0()'
At /opt/microsoft/powershell/6/Modules/PowerShellGet/PSModule.psm1:3128 char:21
+ ... $null = PackageManagement\Install-PackageProvider -Name $script:N ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidOperation: (Microsoft.PowerShel\u2026tallPackageProvider:InstallPackageProvider) [Install-PackageProvider], Exception
+ FullyQualifiedErrorId : UnhandledException,Microsoft.PowerShell.PackageManagement.Cmdlets.InstallPackageProvider
PackageManagement\Import-PackageProvider : No match was found for the specified search criteria and provider name 'NuGet'. Try 'Get-PackageProvider -ListAvailable' to see if the provider exists on the system.
At /opt/microsoft/powershell/6/Modules/PowerShellGet/PSModule.psm1:3134 char:21
+ ... $null = PackageManagement\Import-PackageProvider -Name $script:Nu ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidData: (NuGet:String) [Import-PackageProvider], Exception
+ FullyQualifiedErrorId : NoMatchFoundForCriteria,Microsoft.PowerShell.PackageManagement.Cmdlets.ImportPackageProvider
PackageManagement\Get-PackageProvider : Unhandled Exception - Message:'The type initializer for 'Microsoft.PackageManagement.Internal.Utility.Extensions.FilesystemExtensions' threw an exception.' Name:'TypeInitializationException' Stack Trace:' at Microsoft.PackageManagement.Internal.Utility.Extensions.FilesystemExtensions.MakeSafeFileName(String input)
at Microsoft.PackageManagement.Internal.Utility.Plugin.DynamicType.DefineDynamicType(Type interfaceType)
at Microsoft.PackageManagement.Internal.Utility.Plugin.DynamicType..ctor(Type interfaceType, OrderedDictionary`2 methods, List`2 delegates, List`1 stubs)
at Microsoft.PackageManagement.Internal.Utility.Plugin.DynamicType.<>c__DisplayClass9_0.<Create>b__3()
at Microsoft.PackageManagement.Internal.Utility.Extensions.DictionaryExtensions.GetOrAdd[TKey,TValue](IDictionary`2 dictionary, TKey key, Func`1 valueFunction)
at Microsoft.PackageManagement.Internal.Utility.Plugin.DynamicType.Create(Type tInterface, OrderedDictionary`2 instanceMethods, List`2 delegateMethods, List`1 stubMethods, List`2 usedInstances)
at Microsoft.PackageManagement.Internal.Utility.Plugin.DynamicInterface.CreateProxy(Type tInterface, Object[] instances)
at Microsoft.PackageManagement.Internal.Utility.Plugin.DynamicInterface.DynamicCast(Type tInterface, Object[] instances)
at Microsoft.PackageManagement.Internal.Utility.Plugin.DynamicInterface.DynamicCast[TInterface](Object[] instances)
at Microsoft.PackageManagement.Internal.Utility.Plugin.DynamicInterfaceExtensions.As[TInterface](Object instance)
at Microsoft.PowerShell.PackageManagement.Cmdlets.CmdletBase.get_PackageManagementHost()
at Microsoft.PowerShell.PackageManagement.Cmdlets.CmdletBase.SelectProviders(String name)
at Microsoft.PowerShell.PackageManagement.Cmdlets.GetPackageProvider.ProcessProvidersFilteredByName()
at Microsoft.PowerShell.PackageManagement.Cmdlets.GetPackageProvider.ProcessRecordAsync()
at Microsoft.PowerShell.PackageManagement.Cmdlets.AsyncCmdlet.<>c__DisplayClass83_0.<AsyncRun>b__0()'
+ CategoryInfo : InvalidOperation: (Microsoft.PowerShel\u2026.GetPackageProvider:GetPackageProvider) [Get-PackageProvider], Exception
+ FullyQualifiedErrorId : UnhandledException,Microsoft.PowerShell.PackageManagement.Cmdlets.GetPackageProvider
Install-Module : NuGet provider is required to interact with NuGet-based repositories. Please ensure that '2.8.5.201' or newer version of NuGet provider is installed.
At line:1 char:1
+ Install-Module -Name Az -AllowClobber -Scope CurrentUser -Force
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidOperation: (:) [Install-Module], InvalidOperationException
Environment data
Name Value
---- -----
PSVersion 6.2.2
PSEdition Core
GitCommitId 6.2.2
OS Linux 3.10.0-957.21.3.el7.x86_64 PowerShell/PowerShell#1 SMP Tue Jun 18 16:35:19 UTC 2019
Platform Unix
PSCompatibleVersions {1.0, 2.0, 3.0, 4.0…}
PSRemotingProtocolVersion 2.3
SerializationVersion 1.1.0.1
WSManStackVersion 3.0
SELinux status:
SELinux status: enabled
SELinuxfs mount: /sys/fs/selinux
SELinux root directory: /etc/selinux
Loaded policy name: targeted
Current mode: permissive
Mode from config file: enforcing
Policy MLS status: enabled
Policy deny_unknown status: allowed
Max kernel policy version: 31
The -E
on sudo
says not to load the environment of the user so the environment is pointing to places the user likely doesn't have access to.
Also, I think this is would be considered a feature request for https://github.com/PowerShell/PowerShellget . I don't have permissions to transfer your issue.
GitHub
PowerShellGet is the Package Manager for PowerShell - PowerShell/PowerShellGet
@TravisEz13 thanks for pointing that out. I checked again without -E
and the result are exactly the same.
@SteveL-MSFT Can/Should we transfer this to PowerShellGet?
@djsowa thanks for opening this issue...what version of .Net do you have running?
@SydneyhSmith Here You can find dotnet--info result:
.NET Core SDK (reflecting any global.json):
Version: 2.2.402
Commit: c7f2f96116
Runtime Environment:
OS Name: centos
OS Version: 7
OS Platform: Linux
RID: centos.7-x64
Base Path: /usr/share/dotnet/sdk/2.2.402/
Host (useful for support):
Version: 2.2.7
Commit: b1e29ae826
.NET Core SDKs installed:
2.1.802 [/usr/share/dotnet/sdk]
2.2.402 [/usr/share/dotnet/sdk]
.NET Core runtimes installed:
Microsoft.AspNetCore.All 2.1.13 [/usr/share/dotnet/shared/Microsoft.AspNetCore.All]
Microsoft.AspNetCore.All 2.2.7 [/usr/share/dotnet/shared/Microsoft.AspNetCore.All]
Microsoft.AspNetCore.App 2.1.13 [/usr/share/dotnet/shared/Microsoft.AspNetCore.App]
Microsoft.AspNetCore.App 2.2.7 [/usr/share/dotnet/shared/Microsoft.AspNetCore.App]
Microsoft.NETCore.App 2.1.13 [/usr/share/dotnet/shared/Microsoft.NETCore.App]
Microsoft.NETCore.App 2.2.7 [/usr/share/dotnet/shared/Microsoft.NETCore.App]
To install additional .NET Core runtimes or SDKs:
https://aka.ms/dotnet-download
I am having this issue as well. I think the root cause is having no package provider on the system for the user. The debug log says Try 'Get-PackageProvider -ListAvailable' to see if the provider exists on the system.
When I run that command as a non-root user:
$ pwsh -Command 'Get-PackageProvider -ListAvailable -Verbose -Debug'
DEBUG: 00:00:00.0000076 Trying provider assembly: /usr/local/share/powershell/Modules/PackageManagement/1.4.7/coreclr/netstandard2.0/Microsoft.PackageManagement.NuGetProvider.dll
DEBUG: 00:00:00.0012889 Trying provider assembly: /usr/local/share/powershell/Modules/PackageManagement/1.4.7/coreclr/netstandard2.0/Microsoft.PackageManagement.MetaProvider.PowerShell.dll
DEBUG: 00:00:00.0055790 Attempting loading of assembly: /usr/local/share/powershell/Modules/PackageManagement/1.4.7/coreclr/netstandard2.0/Microsoft.PackageManagement.MetaProvider.PowerShell.dll
DEBUG: 00:00:00.0059795 Trying provider assembly: /usr/local/share/powershell/Modules/PackageManagement/1.4.7/coreclr/netstandard2.0/Microsoft.PackageManagement.ArchiverProviders.dll
DEBUG: 00:00:00.0064290 Attempting loading of assembly: /usr/local/share/powershell/Modules/PackageManagement/1.4.7/coreclr/netstandard2.0/Microsoft.PackageManagement.NuGetProvider.dll
DEBUG: 00:00:00.0066582 Attempting loading of assembly: /usr/local/share/powershell/Modules/PackageManagement/1.4.7/coreclr/netstandard2.0/Microsoft.PackageManagement.ArchiverProviders.dll
DEBUG: 00:00:00.0086715 Trying provider assembly: /usr/local/share/powershell/Modules/PackageManagement/1.4.7/coreclr/netstandard2.0/Microsoft.PackageManagement.CoreProviders.dll
DEBUG: 00:00:00.0090057 Attempting loading of assembly: /usr/local/share/powershell/Modules/PackageManagement/1.4.7/coreclr/netstandard2.0/Microsoft.PackageManagement.CoreProviders.dll
VERBOSE: Acquiring providers for assembly: /usr/local/share/powershell/Modules/PackageManagement/1.4.7/coreclr/netstandard2.0/Microsoft.PackageManagement.CoreProviders.dll
VERBOSE: Acquiring providers for assembly: /usr/local/share/powershell/Modules/PackageManagement/1.4.7/coreclr/netstandard2.0/Microsoft.PackageManagement.NuGetProvider.dll
VERBOSE: Acquiring providers for assembly: /usr/local/share/powershell/Modules/PackageManagement/1.4.7/coreclr/netstandard2.0/Microsoft.PackageManagement.ArchiverProviders.dll
VERBOSE: Acquiring providers for assembly: /usr/local/share/powershell/Modules/PackageManagement/1.4.7/coreclr/netstandard2.0/Microsoft.PackageManagement.MetaProvider.PowerShell.dll
DEBUG: 00:00:00.0811480 Registering providers via metaproviders for assembly Microsoft.PackageManagement.MetaProvider.PowerShell.Internal.PowerShellMetaProvider
DEBUG: 00:00:00.1039611 The type initializer for 'Microsoft.PackageManagement.Internal.Utility.Extensions.FilesystemExtensions' threw an exception.
DEBUG: 00:00:00.1043263 The type initializer for 'Microsoft.PackageManagement.Internal.Utility.Extensions.FilesystemExtensions' threw an exception.
DEBUG: 00:00:00.1054291 One or more errors occurred. (The type initializer for 'Microsoft.PackageManagement.Internal.Utility.Extensions.FilesystemExtensions' threw an exception.)
DEBUG: 00:00:00.1059633 FAILED provider assembly: /usr/local/share/powershell/Modules/PackageManagement/1.4.7/coreclr/netstandard2.0/Microsoft.PackageManagement.NuGetProvider.dll
DEBUG: 00:00:00.1172153 One or more errors occurred. (The type initializer for 'Microsoft.PackageManagement.Internal.Utility.Extensions.FilesystemExtensions' threw an exception.)
DEBUG: 00:00:00.1173914 at System.Threading.Tasks.Task.WaitAllCore(Task[] tasks, Int32 millisecondsTimeout, CancellationToken cancellationToken)
at System.Threading.Tasks.Task.WaitAll(Task[] tasks)
at Microsoft.PackageManagement.Internal.Utility.Extensions.CollectionExtensions.WaitAll(IEnumerable`1 tasks)
at Microsoft.PackageManagement.Internal.Implementation.PackageManagementService.AcquireProviders(String assemblyPath, IHostApi request, Boolean shouldRefreshCache)
DEBUG: 00:00:00.1173972 at System.Threading.Tasks.Task.WaitAllCore(Task[] tasks, Int32 millisecondsTimeout, CancellationToken cancellationToken)
at System.Threading.Tasks.Task.WaitAll(Task[] tasks)
at Microsoft.PackageManagement.Internal.Utility.Extensions.CollectionExtensions.WaitAll(IEnumerable`1 tasks)
at Microsoft.PackageManagement.Internal.Implementation.PackageManagementService.AcquireProviders(String assemblyPath, IHostApi request, Boolean shouldRefreshCache)
DEBUG: 00:00:00.1175321 FAILED provider assembly: /usr/local/share/powershell/Modules/PackageManagement/1.4.7/coreclr/netstandard2.0/Microsoft.PackageManagement.ArchiverProviders.dll
DEBUG: 00:00:00.1175319 FAILED provider assembly: /usr/local/share/powershell/Modules/PackageManagement/1.4.7/coreclr/netstandard2.0/Microsoft.PackageManagement.CoreProviders.dll
DEBUG: 00:00:00.1525318 One or more errors occurred. (The type initializer for 'Microsoft.PackageManagement.Internal.Utility.Extensions.FilesystemExtensions' threw an exception.)
DEBUG: 00:00:00.1527452 at System.Threading.Tasks.Task.WaitAllCore(Task[] tasks, Int32 millisecondsTimeout, CancellationToken cancellationToken)
at System.Threading.Tasks.Task.WaitAll(Task[] tasks)
at Microsoft.PackageManagement.Internal.Utility.Extensions.CollectionExtensions.WaitAll(IEnumerable`1 tasks)
at Microsoft.PackageManagement.Internal.Implementation.PackageManagementService.AcquireProviders(String assemblyPath, IHostApi request, Boolean shouldRefreshCache)
DEBUG: 00:00:00.1528996 FAILED provider assembly: /usr/local/share/powershell/Modules/PackageManagement/1.4.7/coreclr/netstandard2.0/Microsoft.PackageManagement.MetaProvider.PowerShell.dll
VERBOSE: PowerShell meta provider initialization failed.
I even tried this after giving the current user rights to the PowerShell-related local folders
sudo chown -R ec2-user /opt/microsoft/
sudo chown -R ec2-user /usr/local/share/powershell/
I had a similar problem. It was caused by ownership of /tmp/Microsoft.PackageManagement. Only root and the nonroot user who created it were able to install modules. Deleting this directory mitigates the issue, but, of course, only for the user who creates it.
@djsowa we're in the process of refactoring the Install cmdlet and will address this issue then.
@anamnavi Are there any ETA when the issue will be fixed?
I ran into a similar issue that brought me here.
On linux (f35), if I use pwsh as one user & then try a different user ... install-module fails (for the second, and subsequent users). I tracked it down to pwsh creating /tmp/Microsoft.PackageManagement/
, which is owned by the first user (with mode 0700). If I delete that directory manually, then install-module works for user #2, but user #1 now breaks. A different bug?
Hi @abilous-ti and @josephtingiris can you all try the latest PowerShellGetv3 release? We believe it might be resolved there.