无法捕捉可执行文件:无法执行"/snap/dotnet-sdk/152/snap/command-chain/snapcraft-runner":权限被拒绝



安装snap后无法执行dotnet命令

我按照以下说明使用snap安装了.NET 6.0预览版。

安装后,当我尝试执行dotnet命令时,我收到以下错误消息:

cannot snap-exec:cannot exec"snap/dotnet-sdk/152/snap/command-chain/snapcraft runner":许可被拒绝这是因为/snap/dotnet-sdk/152/snap目录只能由root用户访问,并且是一个已安装的文件系统,因此不可能对其进行chmod

我使用的是全新的Ubuntu 20.04安装,所以不应该有任何其他冲突。

快照别名似乎有问题。只需取消对齐快照并符号链接二进制文件即可。

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

然后,您应该能够在没有root权限的情况下调用dotnet --list-sdks

# 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

解决方案参考:https://github.com/dotnet/core/issues/4446#issuecomment-605629427

最新更新