sdk: Global tools are not found on zsh
The below example is for FAKE but I can repro with other global tools as well, such as weeknumber. I tried to remove any profile customizations from my profile by running zsh without them and the problem persists. I’ve provided my PATH as well to show that the global tools dir is in fact in there.
Steps to reproduce
- Have the 2.1 preview SDK installed (2.1.300-rc1-008673)
- run zsh with no profile via
zsh --no-rcs dotnet tool install -g fake-cli --version '5.0.0-*'fake
Expected behavior
The FAKE cli help should display
Actual behavior
The shell reports that fake could not be found.
Known workarounds
- run the command in bash, or
- run the fake command explicitly, via
~/.dotnet/tools/fake
Environment data
dotnet --info output:
.NET Core SDK (reflecting any global.json):
Version: 2.1.300-rc1-008673
Commit: f5e3ddbe73
Runtime Environment:
OS Name: Mac OS X
OS Version: 10.13
OS Platform: Darwin
RID: osx.10.13-x64
Base Path: /usr/local/share/dotnet/sdk/2.1.300-rc1-008673/
Host (useful for support):
Version: 2.1.0-rc1
Commit: eb9bc92051
.NET Core SDKs installed:
1.0.4 [/usr/local/share/dotnet/sdk]
2.0.0 [/usr/local/share/dotnet/sdk]
2.1.4 [/usr/local/share/dotnet/sdk]
2.1.101 [/usr/local/share/dotnet/sdk]
2.1.200 [/usr/local/share/dotnet/sdk]
2.1.300-preview2-008533 [/usr/local/share/dotnet/sdk]
2.1.300-rc1-008673 [/usr/local/share/dotnet/sdk]
.NET Core runtimes installed:
Microsoft.AspNetCore.All 2.1.0-preview2-final [/usr/local/share/dotnet/shared/Microsoft.AspNetCore.All]
Microsoft.AspNetCore.All 2.1.0-rc1-final [/usr/local/share/dotnet/shared/Microsoft.AspNetCore.All]
Microsoft.AspNetCore.App 2.1.0-preview2-final [/usr/local/share/dotnet/shared/Microsoft.AspNetCore.App]
Microsoft.AspNetCore.App 2.1.0-rc1-final [/usr/local/share/dotnet/shared/Microsoft.AspNetCore.App]
Microsoft.NETCore.App 1.0.5 [/usr/local/share/dotnet/shared/Microsoft.NETCore.App]
Microsoft.NETCore.App 1.1.2 [/usr/local/share/dotnet/shared/Microsoft.NETCore.App]
Microsoft.NETCore.App 2.0.0 [/usr/local/share/dotnet/shared/Microsoft.NETCore.App]
Microsoft.NETCore.App 2.0.5 [/usr/local/share/dotnet/shared/Microsoft.NETCore.App]
Microsoft.NETCore.App 2.0.6 [/usr/local/share/dotnet/shared/Microsoft.NETCore.App]
Microsoft.NETCore.App 2.0.7 [/usr/local/share/dotnet/shared/Microsoft.NETCore.App]
Microsoft.NETCore.App 2.1.0-preview2-26406-04 [/usr/local/share/dotnet/shared/Microsoft.NETCore.App]
Microsoft.NETCore.App 2.1.0-rc1 [/usr/local/share/dotnet/shared/Microsoft.NETCore.App]
To install additional .NET Core runtimes or SDKs:
https://aka.ms/dotnet-download
$PATH:
/Users/chethusk/.rbenv/shims:/Users/chethusk/.nodenv/shims:/Applications/Postgres.app/Contents/Versions/latest/bin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/Applications/VMware Fusion.app/Contents/Public:/usr/local/share/dotnet:~/.dotnet/tools:/Library/Frameworks/Mono.framework/Versions/Current/Commands
About this issue
- Original URL
- State: closed
- Created 6 years ago
- Reactions: 23
- Comments: 49 (18 by maintainers)
Commits related to this issue
- dotnet: support global tools on zsh https://github.com/dotnet/cli/issues/9321 — committed to agross/dotfiles by agross 5 years ago
I´ve ran into the same problem today. Got resolved editing ~/.zshrc, and putting a new line with:
This is the answer! Thank so much.
This is going to become a greater usability concern with the next version of macos, where bash is being replaced by zsh.
On Catalina, the default shell is zsh… maybe now time to find a way to fix the installation issue? not just writing how to do it manually 😃
That’s correct, the installer only modifies
PATHfor bash. The instructions printed whendotnet tool installdoesn’t find the tools directory onPATHare also for bash.For zsh, you’ll need to modify your
.zshrcmanually to append~/.dotnet/toolstoPATH.Have you considered simply creating the
/etc/paths.d/dotnet-cli-toolsfile with/Users/username/.dotnet/tools(with the current user name) instead of~/.dotnet/tools?Pros:
Cons:
In my opinion, the pros largely outweight the cons. Not having .NET cli tools work out of the box is a shame.
Even @RickStrahl got bit by this today:
@wli3 the problem is that the message is not visible enough. It says that the installation was successful, so none really care about reading through the info printed. It should be more visible, maybe in yellow as warning.
It seems it not working on fish shell too. Workaround: it works after this command:
Set PATH is tricky on macOS due to path_helper is simple and there is no paths.d. Since in unix, the user are responsible for the PATH configuration. There should be less magic. Maybe a better way is to detect current shell is zsh and print a tailored message that the user can copy paste like the current fallback bash output
We are a few macOS’s in with zsh as a default shell.
Installer still writes
export PATH=$PATH:~/.dotnet/toolswhile it should be writingexport PATH=$HOME/.dotnet/tools:$PATHas zsh does “translate” $HOME, and does not translate tilde.@peterhuene we discussed this in early design. Directly edit Unix user’s profile is not “idiomatic”, even dangerous. And asking user to copy paste adding to path is a good middle ground.
Also that is why we need extra config for auto complete
Yet another casualty: https://github.com/waf/CSharpRepl/issues/36
I see. I created this bug to track it https://github.com/dotnet/sdk/issues/3992
Here is my plan:
We won’t have the same experience as bash shell.
We will print the following instruction.
Detail reason: Mac don’t have a good solution to put user path for all user (/USERNAME/home/.dotnet/tools is different for different user). We currently adding literal
~/.dotnet/toolsfor all users. And that works for bash. But it no longer works for zsh.At the same time, directly adding new lines to
.zprofileis not “idiomatic” for unix. So we can only use existing fallback experience. (bash will have the same experience is you install it via tar.gz).I find there are 3 ways you can detect the application is running on zsh. (a)
$SHELL(b)$ZSH_NAMEand use ©ps -p $$Only (a) can work in a dotnet program. If you run
Console.WriteLine(Environment.GetEnvironmentVariable("ZSH_NAME", EnvironmentVariableTarget.Process));you will get nothing, even when echo$ZSH_NAMEcan give you the value in the same session. I don’t know why at this moment. © won’t work since$$is “the current process”. It can only work for scripts. However, the downside of$SHELLis, it will only give you the default shell. That means if you run zsh on top of bash, we will not detect that. I verified in macOS 10.15 VM if it has $SHELL set. (after runningchsh -s /bin/zsh)I’d be glad to file a separate issue for this as well, but it seems relevant to the discussion: My global tools (within a bash shell on macOS) are not discovered by either
whichor/usr/bin/env, and it would seem to be because these tools are also not expanding the~added toPATHfrom/etc/paths.d/dotnet-cli-tools.I believe this is causing https://github.com/filipw/dotnet-script/issues/409. Manually adding
~/.dotnet/toolstoPATHin my~/.bash_profilefixes this issue, but it’s not an obvious workaround given that calling tools directly likedotnet-scriptworks without it.@wli3 thanks for the information. I think it is easy to find articles to support your opinion on internet on any topics, I can easily find some counter links but I will not do that:)
Let’s go back to the actual issue: the current bug is, dotnet only append its path
~/.dotnet/toolsin .bash_profile. This is a wrong assumption because a lot of ppl are using non-bash.And your proposal is to print some warning in the end of sdk installation, to let user manually tune their PATH settings. I think this is a bad idea, because I never need to do that for other programming languages, it is just not user friendly.
So, are you going to add handling for zsh (.zshrc / .zshenv)? I also think that’s not perfect because there are other shell envs. That’s why my proposal is to add tools to /usr/bin or /usr/local/bin for osx/linux because that will support every shell env.
It is up to you MS guys to decide what to do. But I am pretty sure if you keep the current implementation, then every zsh user who install dotnet core and wants to try dotnet tool, will end up having issue, then they will google, then they will find this github issue. They will be disappointed, but they can workaround by adding
~/.dotnet/toolsto their PATH. Is that what you want? I am not sure 😃Oh also, when I mean add
~/.dotnet/tools, I mean with an expanded tilde (when sourced from.zshrcit would expand). zsh does not support~onPATHlike bash does, i.e. it does not expand~when searching it.