dotnet / core

.NET news, announcements, release notes, and more!
https://dot.net
MIT License
20.93k stars 4.9k forks source link

Cannot run dotnet command after installing 6.0 RC/preview using snap #4446

Closed nikonthethird closed 2 years ago

nikonthethird commented 4 years ago

The dotnet command cannot be executed after installing snap

General

I followed these instructions to install the .NET 5.0 preview using snap.

After installation, when I try to execute the dotnet command, I get the following error message:

cannot snap-exec: cannot exec "/snap/dotnet-sdk/67/snap/command-chain/snapcraft-runner": permission denied

This is because the directory /snap/dotnet-sdk/67/snap is only accessible by root and is a mounted file system, so it is not possible to chmod it.

I am using a fresh Ubuntu 18.04 install, so there should not be any other conflicts.

igoventura commented 4 years ago

Try running sudo chmod -R 777 your_directory.

nikonthethird commented 4 years ago

That actually cannot work, since snaps are mounted as a read-only filesystem. This is in the output of my lsblk command:

loop16   7:16   0 113,7M  1 loop /snap/dotnet-sdk/67

So when I try to execute sudo chmod -R 777 /snap/dotnet-sdk/67 I get lots of Read-only file system errors.

This is what the output of ls -sail /snap/dotnet/67 looks like, you can see that the snap folder is onnly accessible by root:

PS /snap/dotnet-sdk/67> ls -sail
total 157
  3067   0 drwxr-xr-x 12 root root    249 Mär 13 03:14 .
917540   4 drwxr-xr-x  3 root root   4096 Mär 27 00:43 ..
     3 112 -rwxr-xr-x  1 root root 114576 Mär 13 03:13 dotnet
     4   0 drwxr-xr-x  4 root root     38 Mär 13 03:13 etc
     9   0 drwxr-xr-x  3 root root     26 Mär 13 03:13 host
    13   0 drwxr-xr-x  3 root root     39 Mär 13 03:13 lib
     1   2 -rw-r--r--  1 root root   1116 Feb 21 00:37 LICENSE.txt
    24   0 drwxr-xr-x  2 root root     32 Mär 13 03:14 meta
    26   0 drwxr-xr-x  6 root root    183 Mär 13 03:13 packs
   696   0 drwxr-xr-x  3 root root     48 Mär 13 03:13 sdk
  2387   0 drwxr-xr-x  4 root root     88 Mär 13 03:13 shared
  2715   0 drwx------  3 root root     36 Mär 13 03:14 snap
  2718   0 drwxr-xr-x  3 root root     46 Mär 13 03:13 templates
     2  40 -rw-r--r--  1 root root  39960 Feb 21 00:37 ThirdPartyNotices.txt
  2729   0 drwxr-xr-x  4 root root     51 Mär 13 03:13 usr

So this is not something easily fixed by changing file permissions.

igoventura commented 4 years ago

So try running sudo dotnet.

I've installed Ubuntu on my machine and sudo dotnet worked.

nikonthethird commented 4 years ago

Yes, that does indeed do something. However, any downloaded Nuget packages will be owned by root, so you have to manually chown the Nuget cache directory every time. And furthermore the tooling does not work, the C# extension of VS Code will not work if your dotnet command requires sudo to work.

The regular snap package (snap install dotnet-sdk) works without sudo, so this is definitely an issue in the snap package, and until it is resolved, the snap package can only be used from the command line with sudo and the tooling will not work.

faahiero commented 4 years ago

if you run sudo snap run dotnet-sdk.dotnet it will work. Why? It's a snap bug?

nikonthethird commented 4 years ago

if you run sudo snap run dotnet-sdk.dotnet it will work. Why? It's a snap bug?

Yes, I think it is a problem in the snap package itself, the folder permissions are wrong. I don't know how to work around this, though, because the snap package is mounted as read-only and I have no idea where the mounted file itself is located.

nikonthethird commented 4 years ago

I found a workaround. It is possible to fix the snap package :)

These are the commands I used to find where the actual package file is located, extract it to a new location, fix the permissions, create a new package and replace the old one:

Note: I updated this workaround for the .NET 6 snap.

# Install the .NET 6 SDK as a snap package.
# The snap package will automatically be mounted.
snap install dotnet-sdk --channel=6.0/beta --classic

# Try running the snap command. If this works, you do not have to
# apply the workaround. If this fails, continue.
dotnet-sdk.dotnet --version

# To find out where the snap package has been mounted,
# list all block devices and look for /snap/dotnet-sdk/
# in the MOUNTPOINT column. Remember the name of the loop
# device.
lsblk

# To get the actual path of the snap package file, run
# the following command with the name of the loop device.
# Replace XXX with the number of your loop device.
# The path in the BACK-FILE column points to the snap package.
losetup --list /dev/loopXXX

# Create a folder where we're extracting the snap package into.
mkdir dotnet-snap-fix
cd dotnet-snap-fix

# Extract the snap package into this directory.
# Add the correct BACK-FILE path to your snap package here.
# Replace XXX or the whole path with the BACK-FILE displayed by
# the losetup command above.
sudo unsquashfs /var/lib/snapd/snaps/dotnet-sdk_XXX.snap

# Change the permissions of the snap folder containing the runner
# to be readable and executable. This will fix the permission problem.
sudo chmod -R +rx ./squashfs-root/snap/

# Create a new snap package with the changed permissions.
# Make sure to use the same file name as in the BACK-FILE path.
# Replace XXX or the whole file name with the file name of the
# BACK-FILE path displayed by the losetup command above.
sudo mksquashfs ./squashfs-root/ dotnet-sdk_XXX.snap -comp xz -all-root

# Overwrite the old snap package with our new one.
# Make sure the file name is correct (same as in BACK-FILE).
sudo mv ./dotnet-sdk_XXX.snap /var/lib/snapd/snaps/

# Finally reboot your machine so the changes are detected.
sudo reboot

# Do not use snap disable / snap enable, they will replace the
# fixed snap package with the broken one again.
# After the reboot, the dotnet-sdk.dotnet command will work without sudo.
dotnet-sdk.dotnet

After that horrendous "fix", the command works without sudo:

PS /home/nikon> dotnet-sdk.dotnet --version
6.0.100-rc.2.21505.57
faahiero commented 4 years ago

It works like a charm! Thanks for the help. I hope MS fix this in future versions!

nikonthethird commented 4 years ago

Preview 2 no longer has this issue.

kzu commented 3 years ago

I'm on 5.0.100-preview.3.20216.6 (installed via sudo snap install) and it has this issue.

$ snap info dotnet-sdk

name:      dotnet-sdk
summary:   Develop high performance applications in less time, on any platform.
publisher: Microsoft .NET Core (dotnetcore✓)
contact:   https://dot.net/core
license:   unset
description: |
  .NET Core is the modular and high performance implementation of .NET for creating web applications
  and services that run on Windows, Linux and Mac. It is open source and it can share the same code
  with .NET Framework and Xamarin apps.

  .NET Core is a .NET Foundation project. https://dotnetfoundation.org/
commands:
  - dotnet-sdk.dotnet
snap-id:      uHc4y9lWxyqYfxsqcr4xILzAai4L1BHs
tracking:     5.0/edge
refresh-date: today at 13:01 UTC
channels:
  stable:        –
  candidate:     –
  beta:          –
  edge:          5.0.100-preview.3.20216.6 2020-04-22 (79) 127MB classic
  5.0/stable:    –
  5.0/candidate: –
  5.0/beta:      –
  5.0/edge:      5.0.100-preview.3.20216.6 2020-04-21 (79) 127MB classic
installed:       5.0.100-preview.3.20216.6            (79) 127MB classic

Error on run:

$ dotnet-sdk.dotnet
/snap/dotnet-sdk/79/snap/command-chain/snapcraft-runner: 3: exec: /snap/dotnet-sdk/79/dotnet: not found

Also, the "horrid fix" steps didn't fix it. Ended up with the same error after the reboot 😢

I'm on a raspberry pi 4 B:

    description: Computer
    product: Raspberry Pi 4 Model B Rev 1.4
    serial: 10000000d5e618a2
    width: 64 bits
    capabilities: smp cp15_barrier setend swp tagged_addr_disabled
Nezz commented 3 years ago

We're seeing this issue with .NET 5.0.400:

snap run dotnet-sdk.dotnet
cannot snap-exec: cannot exec "/snap/dotnet-sdk/137/snap/command-chain/snapcraft-runner": permission denied

Downgrading the snap package resolved it.

Tasty213 commented 3 years ago

Also seeing this issue, but when i run snap revert is shows: sudo snap revert dotnet error: cannot revert "dotnet": no revision to revert to

mbxsuite commented 3 years ago

same here for .NET 5.0.400

FrenchTastic commented 3 years ago

@Tasty213 The package name is dotnet-sdk.

sudo snap revert dotnet-sdk

Should do the trick.

merto-dvp commented 3 years ago

Same issue here also, version latest/stable: 5.0.400, installed with snap.

Installing latest/edge: 5.0.202 2021-04-16 (120) 137MB classic) fixed my issue for now.

snap remove dotnet-sdk snap install dotnet-sdk --classic --channel=latest/edge

You can see the versions with snap info dotnet-sdk command.

n84ck commented 3 years ago

Same issue here .NET 3.1.412. Snap revert worked. Can I hold the snap packages somehow?

merto-dvp commented 3 years ago

Also seeing this issue, but when i run snap revert is shows: sudo snap revert dotnet error: cannot revert "dotnet": no revision to revert to

This is a temporary fix but, worked fine for me.

snap info dotnet-sdk to check versions.

channels:
  latest/stable:    5.0.400                   2021-08-10 (137) 139MB classic
  latest/candidate: ↑
  latest/beta:      ↑
  latest/edge:      5.0.202                   2021-04-16 (120) 137MB classic
  lts/stable:       3.1.412                   2021-08-10 (136) 123MB classic

After that you can remove the sdk with snap remove dotnet-sdk then install the version you want with snap install dotnet-sdk --classic --channel=<insert_channel_here>

saginadir commented 3 years ago

@Tasty213 The package name is dotnet-sdk.

sudo snap revert dotnet-sdk

Should do the trick.

Worked for me. Thanks!

Artur-Cavalcante commented 3 years ago

@Tasty213 The package name is dotnet-sdk. sudo snap revert dotnet-sdk Should do the trick.

Worked for me. Thanks!

Me too :)

ar0311 commented 3 years ago

Also getting this issue with .NET 6.0 preview 7 snap.

sudo snap revert dotnet-sdk worked, however it's no longer preview 7 but preview 6 which is a bit pointless

YousefSaber commented 3 years ago

@Tasty213 The package name is dotnet-sdk.

sudo snap revert dotnet-sdk

Should do the trick.

didn't work with me

sudo snap revert dotnet-sdk
error: cannot revert "dotnet-sdk": no revision to revert to

also, the issue is still present with the latest stable dotnet app version

dotnet-sdk               5.0.400                     137    latest/stable    dotnetcore✓  classic
dotnet --version
cannot snap-exec: cannot exec "/snap/dotnet-sdk/137/snap/command-chain/snapcraft-runner": permission denied
hexiy commented 3 years ago

Hope this gets resolved soon, but atleast the fix worked :)

After that horrendous "fix", the command works without sudo:

savakarrohan commented 3 years ago

Why would the dotnet package be installed under root permission?

j0g3sc commented 3 years ago

For dotnet-sdk-3.1 the following worked for me:

wget https://packages.microsoft.com/config/ubuntu/20.04/packages-microsoft-prod.deb -O packages-microsoft-prod.deb
sudo dpkg -i packages-microsoft-prod.deb
rm packages-microsoft-prod.deb

Then

sudo apt-get update; \
  sudo apt-get install -y apt-transport-https && \
  sudo apt-get update && \
  sudo apt-get install -y dotnet-sdk-3.1

source: https://docs.microsoft.com/en-us/dotnet/core/install/linux-ubuntu#2004-

ar0311 commented 3 years ago

Thats for the deb package. This issue is regarding installation using snap package.

BDisp commented 3 years ago

The @nikonthethird workaround fix the "permission denied", thanks. Nonetheless, when I do a "dotnet clean" and then "dotnet build" I receive the following error randomly. Anyone know why? On WSL2 I never get this error, regardless of the times I repeat it. Will it be related to the snap bug?

/snap/dotnet-sdk/137/sdk/5.0.400/Sdks/Microsoft.NET.Sdk/targets/Microsoft.NET.Sdk.targets(464,5): error NETSDK1029: Unable to use '/snap/dotnet-sdk/137/packs/Microsoft.NETCore.App.Host.linux-x64/5.0.9/runtimes/linux-x64/native/apphost' as application host executable as it does not contain the expected placeholder byte sequence '63-33-61-62-38-66-66-31-33-37-32-30-65-38-61-64-39-30-34-37-64-64-33-39-34-36-36-62-33-63-38-39-37-34-65-35-39-32-63-32-66-61-33-38-33-64-34-61-33-39-36-30-37-31-34-63-61-65-66-30-63-34-66-32' that would mark where the application name would be written

BDisp commented 3 years ago

This also happens on a Debian distro at /usr/share/dotnet/. Only on the second time doing dotnet build, builds successfully. I'm using VirtualBox shared folders.

/usr/share/dotnet/sdk/5.0.400/Sdks/Microsoft.NET.Sdk/targets/Microsoft.NET.Sdk.targets(464,5): error NETSDK1029: Unable to use '/usr/share/dotnet/packs/Microsoft.NETCore.App.Host.linux-x64/5.0.9/runtimes/linux-x64/native/apphost' as application host executable as it does not contain the expected placeholder byte sequence '63-33-61-62-38-66-66-31-33-37-32-30-65-38-61-64-39-30-34-37-64-64-33-39-34-36-36-62-33-63-38-39-37-34-65-35-39-32-63-32-66-61-33-38-33-64-34-61-33-39-36-30-37-31-34-63-61-65-66-30-63-34-66-32' that would mark where the application name would be written.

BDisp commented 3 years ago

We're seeing this issue with .NET 5.0.400:

snap run dotnet-sdk.dotnet
cannot snap-exec: cannot exec "/snap/dotnet-sdk/137/snap/command-chain/snapcraft-runner": permission denied

I already figured out how to fix this issue on Ubuntu 20.04.3 LTS (Focal Fossa) with snap 2.51.4:

Remove from snap:
~$ sudo snap remove dotnet-sdk

The hash still exist:
~$ type dotnet
dotnet is hashed (/snap/bin/dotnet)

Remove the hash from bash:
~$ hash -r dotnet
bash: hash: dotnet: not found

Check it again::
~$ type dotnet
bash: type: dotnet: not found

Install dotnet-sdk:
~$ sudo snap install dotnet-sdk --classic
dotnet-sdk 5.0.400 from Microsoft .NET Core (dotnetcore✓) installed

~$ dotnet

Usage: dotnet [options]
Usage: dotnet [path-to-application]

Options:
  -h|--help         Display help.
  --info            Display .NET information.
  --list-sdks       Display the installed SDKs.
  --list-runtimes   Display the installed runtimes.

path-to-application:
  The path to an application .dll file to execute.

~$ dotnet --info
.NET SDK (reflecting any global.json):
 Version:   5.0.400
 Commit:    d61950f9bf

Runtime Environment:
 OS Name:     ubuntu
 OS Version:  20.04
 OS Platform: Linux
 RID:         ubuntu.20.04-x64
 Base Path:   /snap/dotnet-sdk/137/sdk/5.0.400/

Host (useful for support):
  Version: 5.0.9
  Commit:  208e377a53

.NET SDKs installed:
  5.0.400 [/snap/dotnet-sdk/137/sdk]

.NET runtimes installed:
  Microsoft.AspNetCore.App 5.0.9 [/snap/dotnet-sdk/137/shared/Microsoft.AspNetCore.App]
  Microsoft.NETCore.App 5.0.9 [/snap/dotnet-sdk/137/shared/Microsoft.NETCore.App]

To install additional .NET runtimes or SDKs:
  https://aka.ms/dotnet-download

There is no needs to reboot.

psychoslave commented 3 years ago

Same issue on an Ubuntu 21.04 with snap 2.51.4.

@merto-dvp solution seems to work, but of course you have to be okay with an edge version:

snap remove dotnet-sdk
snap install dotnet-sdk --classic --channel=latest/edge
murbanowicz commented 3 years ago

Same issue with NET 6 preview 7 on Fedora 34

rogierhofboer commented 3 years ago

Same issue for rc1 6.0.100-rc.1.21458.32 snap. The fix of @nikonthethird works. but you'll need to replace dotnet-sdk_67.snap with dotnet-sdk_142.snap tip: the number to use is shown in the error message ;)

Thanks for this fix @nikonthethird ! Could someone please re-open this issue until a permanent fix is available?

bibble235 commented 3 years ago

@nikonthethird Thanks for the help with this. I am on ubuntu hirsute btw

asinyagin commented 3 years ago

I have got the same issue with latest/stable 5.0.402. Thanks to @nikonthethird for the workaround!

chuanqisun commented 3 years ago

Had same issue. Switching to latest/edge works.

Diagnostics

# uname
Linux pop-os 5.13.0-7614-generic #14~1631647151~21.04~930e87c-Ubuntu SMP Fri Sep 17 00:24:58 UTC  x86_64 x86_64 x86_64 GNU/Linux

# snap --version
snap    2.51.7
snapd   2.51.7
series  16
pop     21.04
kernel  5.13.0-7614-generic

Just want to point out, the latest/edge channel (5.0.202) is actually older than latest/stable (5.0.402), so this is a regression, and there is a high risk that the workaround will stop working as soon as latest/edge channel gets a version bump. It would be nice if @nikonthethird could re-open this issue so the dotnet team knows that the problem is unresolved.

image

nikonthethird commented 2 years ago

As requested, I will re-open this old issue since the same thing is wrong in the 6.0.0-rc.2.21480.5 snap. I will also update the fix.

zezba9000 commented 2 years ago

Same issue for me on Ubuntu 20.04 & PopOS 21.04 Trying to install .NET 5

cannot snap-exec: cannot exec "/snap/dotnet-sdk/144/snap/command-chain/snapcraft-runner": permission denied

luka1231123 commented 2 years ago

thanks nikonthethird works like a charm

leecow commented 2 years ago

It appears this permissions issue related to the automatic dotnet alias registered with the Snap. I'll look further into that with the Snapcraft folks. In the meantime, I have been able to work around this on 18.04, 20.04 (21.04 is segfaulting so something additional is happening there), Fedora 33 and OpenSUSE by sym linking the current Snap install dotnet with sudo ln -s /snap/dotnet-sdk/current/dotnet /usr/local/bin/dotnet. You'll need to close the current terminal instance for the symlink to begin taking precedence.

zezba9000 commented 2 years ago

Flatpak is a much better system as MS can host the repository while Snap you can't. If Snap keeps breaking... might consider that. Flatpak was also better setup for permission issues I believe.

alissonperim commented 2 years ago

@nikonthethird thanks dude, it works beaut here. If i was close to you, I would certainly pay a coke for you :1st_place_medal:

3steve3 commented 2 years ago

Issue still present on 6.0.101. Workaround works.

acjohnson commented 2 years ago

I followed the official instructions for installing dotnet sdk 6.0 https://docs.microsoft.com/en-us/dotnet/core/install/linux-snap on Ubuntu 21.04 and ended up here. How is this still and problem yet this issue is closed?

zezba9000 commented 2 years ago

"How is this still and problem yet this issue is closed?" -- MS loves Linux didn't you know?

But for real if Snap has this many problems MS... please use Flatpak... kinda ridicules as this point. At least update your docs to reflect what works.

wilx commented 2 years ago

This is still an issue.

> dotnet
cannot snap-exec: cannot exec "/snap/dotnet-sdk/152/snap/command-chain/snapcraft-runner": permission denied

This is with 6.0.101.

boonkerz commented 2 years ago

same issue here

chaosrun commented 2 years ago

Same issue with 6.0.101

debevv commented 2 years ago

I confirm the issue with 6.0.101 on Ubuntu 21.10

$ dotnet
cannot snap-exec: cannot exec "/snap/dotnet-sdk/152/snap/command-chain/snapcraft-runner": permission denied
zigpot commented 2 years ago

Seems like this problem still persists across all .NET 6.0 versions. ❌ latest/stable: 6.0.101 ✅ latest/edge: 5.0.202 ❌ lts/stable: 6.0.101 ❌ 6.0/stable: 6.0.101 ❌ 6.0/beta: 6.0.100-rc.2.21505.57 2021-10-12 (145) ✅ 5.0/stable: 5.0.404 ✅ 3.1/stable: 3.1.416 ❌ 2.1/stable: 2.1.818

Best solution would be to use version 5 like @merto-dvp's or @nikonthethird's if you need version 6.

-- Debian 11 x64

Xeevis commented 2 years ago

It appears to be problem with snap alias. Just unalias the snap and symlink the binary instead.

sudo snap unalias dotnet
sudo ln -s /snap/dotnet-sdk/current/dotnet /usr/local/bin/dotnet

You should then be able to call dotnet --list-sdks without root permission.

Amartain commented 2 years ago

It still doesn't work... with the 6th version of .net - tried changing the alias however the snap libraries don't look like that for me. @Xeevis