Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
nikonthethird opened this issue Mar 24, 2020 · 61 comments · Fixed by dotnet/installer#12618
Closed

Comments

@nikonthethird
Copy link

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
Copy link

Try running sudo chmod -R 777 your_directory.

@nikonthethird
Copy link
Author

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
Copy link

igoventura commented Mar 27, 2020

So try running sudo dotnet.

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

@nikonthethird
Copy link
Author

nikonthethird commented Mar 28, 2020

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
Copy link

faahiero commented Mar 29, 2020

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

@nikonthethird
Copy link
Author

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
Copy link
Author

nikonthethird commented Mar 29, 2020

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
Copy link

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

@nikonthethird
Copy link
Author

Preview 2 no longer has this issue.

@kzu
Copy link

kzu commented May 18, 2021

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
Copy link

Nezz commented Aug 11, 2021

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
Copy link

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
Copy link

same here for .NET 5.0.400

@FrenchTastic
Copy link

@Tasty213
The package name is dotnet-sdk.

sudo snap revert dotnet-sdk

Should do the trick.

@merto-dvp
Copy link

merto-dvp commented Aug 11, 2021

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
Copy link

n84ck commented Aug 11, 2021

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

@merto-dvp
Copy link

merto-dvp commented Aug 11, 2021

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
Copy link

@Tasty213
The package name is dotnet-sdk.

sudo snap revert dotnet-sdk

Should do the trick.

Worked for me. Thanks!

@Artur-Cavalcante
Copy link

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

Worked for me. Thanks!

Me too :)

@ar0311
Copy link
Contributor

ar0311 commented Aug 14, 2021

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
Copy link

@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
Copy link

hexiy commented Aug 24, 2021

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

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

@savakarrohan
Copy link

Why would the dotnet package be installed under root permission?

@j0g3sc
Copy link

j0g3sc commented Aug 27, 2021

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
Copy link
Contributor

ar0311 commented Aug 27, 2021

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

@BDisp
Copy link

BDisp commented Sep 2, 2021

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
Copy link

BDisp commented Sep 3, 2021

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.

@leecow
Copy link
Member

leecow commented Oct 29, 2021

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
Copy link

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
Copy link

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

@3steve3
Copy link

3steve3 commented Dec 26, 2021

Issue still present on 6.0.101. Workaround works.

@acjohnson
Copy link

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
Copy link

zezba9000 commented Dec 31, 2021

"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
Copy link

wilx commented Jan 12, 2022

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
Copy link

same issue here

@chaosrun
Copy link

Same issue with 6.0.101

@debevv
Copy link

debevv commented Jan 19, 2022

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
Copy link

zigpot commented Jan 26, 2022

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
Copy link

Xeevis commented Jan 31, 2022

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
Copy link

Amartain commented Feb 1, 2022

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

@zigpot
Copy link

zigpot commented Feb 18, 2022

This problem is fixed with version 7.0.0 in case anyone doesn't mind upgrading from 6.0

@signor-mike
Copy link

Had the same issue on Ubuntu.
Removed snap and installed as apt. Works like a charm.

Replace 5.0 with desired version :)

sudo snap remove dotnet-sdk // if needed

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

sudo apt update

sudo apt install apt-transport-https

sudo apt-get install -y dotnet-sdk-5.0

And now dotnet --version gives me correct output, without sudo. Hallelujah
https://stackoverflow.com/questions/69842779/permision-denied-for-dotnet

@CapTearow
Copy link

This is still an issue with snap and even on the 7.0 version on my side.

I use Solus so I don't have a native version on the repo so "install as apt" is not a solution on my side.

@ksandaru
Copy link

ksandaru commented Jul 9, 2022

On my raspberry pi I installed .Net runtime and .Net core SDK. But, it only shows runtime and it can not find the SDK.

.NET Core SDKs installed:
No SDKs were found.

.NET Core runtimes installed:
Microsoft.NETCore.App 2.1.3 [/home/pi/dotnet/shared/Microsoft.NETCore.App]

(Used resource: https://snapcraft.io/install/dotnet-sdk/raspbian)

@tznind
Copy link

tznind commented Jul 10, 2022

On my raspberry pi I installed .Net runtime and .Net core SDK. But, it only shows runtime and it can not find the SDK.

Try looking in /root/.dotnet. Thats where it installed for me. Furthermore I have to use sudo -s for permissions to run the dotnet command and it isn't configured to be on $PATH. All in all very suboptimal. This was using the dotnet_install.sh file.

@ksandaru
Copy link

ksandaru commented Jul 10, 2022

@tznind
I installed .NET SDK 3.1 on Raspberry pi 3b by referring Microsoft documentations. Then the runtime and SDK both were installed successfully.(Using Snap, the SDK couldn't be loaded)
https://dotnet.microsoft.com/en-us/download/dotnet/3.

But, VS code shows the same error..(dotnet not found)
sdk installed
Capture1
1

@tznind
Copy link

tznind commented Jul 10, 2022

Ah that looks like WinForms. I think you can't compile WinForms on linux. If you can compile a basic app e.g. dotnet new console then that might be the issue.

See https://stackoverflow.com/questions/60912058/how-to-install-and-use-winforms-in-vscode-on-linux

@zezba9000
Copy link

@ksandaru You can only use WinForms on Linux if you use the Mono Runtime.
Install mono & use that instead.

@ksandaru
Copy link

@ksandaru You can only use WinForms on Linux if you use the Mono Runtime.
Install mono & use that instead.

I saw many articles that saying mono is deprecated..mono still works??

@zezba9000
Copy link

@ksandaru Mono runtime is still under active development and is what powers C# apps to run on Android, iOS & WASM etc.
The WinForms framework should even be considered depreciated on Windows.

If you're just trying to get legacy software to work on Linux with WinForms use Mono.
If you're creating a new project don't use WinForms.

@ksandaru
Copy link

@ksandaru Mono runtime is still under active development and is what powers C# apps to run on Android, iOS & WASM etc.
The WinForms framework should even be considered depreciated on Windows.

If you're just trying to get legacy software to work on Linux with WinForms use Mono.
If you're creating a new project don't use WinForms.

Thank you..got it!

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

Successfully merging a pull request may close this issue.