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

Ruby Gem Installation using asdf doesn't work with ZSH #837

Closed
jctbog9 opened this issue Dec 17, 2020 · 2 comments
Closed

Ruby Gem Installation using asdf doesn't work with ZSH #837

jctbog9 opened this issue Dec 17, 2020 · 2 comments

Comments

@jctbog9
Copy link

jctbog9 commented Dec 17, 2020

When installing asdf on a new machine, I always run into the problem of the ruby gem installation path not being set up properly with asdf. I use ZSH and am always having to run through documentation trying to figure out how to fix this problem after installing and setting up asdf.

The error that pops up when trying to run gem install is

    You don't have write permissions for the /Library/Ruby/Gems/2.6.0 directory.

where it is trying to write directly to the machine's directory for the core mac ruby, rather than asdf's version of it.

I was able to fix this by modifying the path as the documentation suggests by running echo -e "\n. $(brew --prefix asdf)/asdf.sh" >> ~/.zshrc but what I had to research a bit more was that I also needed to add a .tool-versions file to my home directory manually and also manually add the specific ruby version I wanted to run/make changes to.

ruby 2.7.1

Would it be possible to either:
a) make the docs a bit clearer when selecting the desired instructions for installation by stating something like "You may encounter issues with gem installation paths in newer versions of MacOS even after reshim, if so please reference these docs here" when the user selects the ZSH option? Similar to the below warning screenshot?
image

or

b) add a fetaure to the asdf cli that includes the option fix_ruby or something that asks the user what type of shell they are using and then changes the paths automatically based on user input in the terminal (> zsh)? Similar to how NuxtJS CLI asks for input before creating a new app (i.e. which frontend css framework you'd like preinstalled and which testing framework you want preinstalled as well)
image

Just an idea I had but this comes up every time when using asdf on a new machine and trying to work with ruby gems so I figured I'd raise the suggestion here :)

@jthegedus
Copy link
Contributor

jthegedus commented Dec 18, 2020

Hi @jctbog9 I'm sorry you're running into this issue often. The issue here is specifically brew and that it does not actually setup asdf at all, it merely ensures required dependencies are on your system and clones the repo. There are a few other steps to get asdf setup properly (these steps are the top of the docs page https://asdf-vm.com/#/core-manage-asdf):

  1. Manage asdf: install asdf and add asdf to your shell
    1.1 restart your shell or source your shells config
  2. Manage Plugins: add a plugin for your tool asdf plugin add nodejs
  3. Manage Versions: install a version of that tool asdf install nodejs 13.14.0
  4. Configuration: set global or project tool versions via .tool-versions config

The asdf core team did not create the Brew Formula and unfortunately have been declined to get the brew installation of asdf to log further steps to users. See #785 and Homebrew/homebrew-core#54315

From the order of steps you describe I assume this is what you experienced:

  1. gem install before asdf is added to the shell config and shell config re-sourced (or shell restarted) gem uses the system installation of ruby
  2. go to docs site, see macOS instructions, add asdf to your shell
  3. still have issues with No version set for command gem error as no config file was detected (This specific issue was also reported yesterday by another Homebrew installation - There is no way to silence spurious "No version set for command" warnings. #838)
  4. research the error in GitHub and add $HOME/.tool-versions with ruby 2.7.2
  5. issue finally resolved

Unfortunately, because asdf.sh is not run until it is added to your shells config (second part of setup step 1), asdf has no way to notify you that it is not running or needs further setup etc, so you just get the system ruby version and all it's shims.

Hopefully now it is clear this isn't an issue specific to Ruby or Gems, but more asdf setup of which there is a history of issues with brew installations and the knowledge transfer that asdf requires further steps than brew performs.

Regarding your suggestion to automatically setup asdf after some questions to the user, we (asdf core) have found that our user base have such diverse system configurations that automatically configuring asdf is too much work and involve too many concessions in areas we think are security concerns for users.

Feel free to reopen should you not feel the root cause is addressed :)

@ndrslmpk
Copy link

ndrslmpk commented May 5, 2023

Has this issue been solved so far?

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

No branches or pull requests

3 participants