繁体   English   中英

无法 snap-exec:无法执行“/snap/dotnet-sdk/152/snap/command-chain/snapcraft-runner”:权限被拒绝

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

安装 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 安装,所以不应该有任何其他冲突。

# 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

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

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

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

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM