'cannot snap-exec: cannot exec "/snap/dotnet-sdk/152/snap/command-chain/snapcraft-runner": permission denied
The dotnet command cannot be executed after installing snap
I followed these instructions to install the .NET 6.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/152/snap/command-chain/snapcraft-runner": permission denied This is because the directory /snap/dotnet-sdk/152/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 20.04 install, so there should not be any other conflicts.
Solution 1:[1]
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.
Solution 2:[2]
# 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 path in the BACK-FILE column points to the snap package.
losetup --list
# Replace XXX with the number of your snap.
# find the /var/lib/snapd/snaps/dotnet-sdk_XXX.snap in the list
# 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
reference to solution: https://github.com/dotnet/core/issues/4446#issuecomment-605629427
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Xeevis |
| Solution 2 | Ali Raza |
