williamboman / mason.nvim

Portable package manager for Neovim that runs everywhere Neovim runs. Easily install and manage LSP servers, DAP servers, linters, and formatters.
Apache License 2.0
7.63k stars 270 forks source link

Cannot install Solargraph, Mason is trying to install using a different Ruby version #1493

Open zachschultz opened 1 year ago

zachschultz commented 1 year ago

I've searched open issues for similar requests

I've recently downloaded the latest plugin version of mason.nvim

Problem description

I'm trying to install solargraph via Mason (:MasonInstall solargraph) and it's failing when attempting to build native extensions with the following error:

ERROR:  Error installing solargraph:
  rubocop requires Ruby version >= 2.7.0. The current ruby version is 2.6.10.210.

Running :checkhealth I can see the following info about NeoVim, Mason, and the running Ruby version:

mason.nvim [Languages] ~
...
- OK Ruby: `ruby 3.1.3p185 (2022-11-24 revision 1a6b16756e) [arm64-darwin22]`
- OK RubyGem: `3.3.26`
...
Ruby provider (optional) ~
- Ruby: ruby 3.1.3p185 (2022-11-24 revision 1a6b16756e) [arm64-darwin22]
- Host: /Users/zach/.rbenv/shims/neovim-ruby-host
- OK Latest "neovim" gem is installed: 0.9.1

Expected behavior

Based on my :checkhealth output, I would expect Mason to use my active version of Ruby to attempt the install, but it seems to be using a completely different one.

Affected packages

solargraph

Mason output

Failed
    ◍ solargraph
      ▼ Displaying full log
        Installing gem solargraph@0.49.0…
        Successfully installed yard-0.9.34
        Successfully installed tilt-2.2.0
        Successfully installed thor-1.2.2
        Successfully installed unicode-display_width-2.4.2
        Successfully installed ruby-progressbar-1.13.0
        Building native extensions. This could take a while...
        Successfully installed racc-1.7.1
        Successfully installed ast-2.4.2
        Successfully installed parser-3.2.2.3
        Successfully installed rubocop-ast-1.29.0
        Successfully installed rexml-3.2.6
        Successfully installed regexp_parser-2.8.1
        Successfully installed rainbow-3.1.1
        Successfully installed parallel-1.23.0
        Successfully installed language_server-protocol-3.17.0.3
        Building native extensions. This could take a while...
        ERROR:  Error installing solargraph:
            rubocop requires Ruby version >= 2.7.0. The current ruby version is 2.6.10.210.
        Successfully installed json-2.6.3
        Successfully installed base64-0.1.1
        spawn: gem failed with exit code 1 and signal 0. 

### Installation log

```Text
[INFO  Tue Sep  5 14:45:27 2023] ...e/nvim/lazy/mason.nvim/lua/mason-core/installer/init.lua:184: Executing installer for Package(name=solargraph) {}
[ERROR Tue Sep  5 14:45:48 2023] ...e/nvim/lazy/mason.nvim/lua/mason-core/installer/init.lua:249: Installation failed for Package(name=solargraph) error=spawn: gem failed with exit code 1 and signal 0. 

### Neovim version (>= 0.7)

NVIM v0.9.1
Build type: Release
LuaJIT 2.1.0-beta3

### Operating system/version

Darwin Zachs-MacBook-Pro.local 22.6.0 Darwin Kernel Version 22.6.0: Wed Jul  5 22:22:05 PDT 2023; root:xnu-8796.141.3~6/RELEASE_ARM64_T6000 arm64

### Healthcheck

```Text
==============================================================================
mason: require("mason.health").check()

mason.nvim ~
- OK mason.nvim version v1.7.0
- OK PATH: prepend
- OK Providers: 
  mason.providers.registry-api
  mason.providers.client
- OK neovim version >= 0.7.0

mason.nvim [Registries] ~
- OK Registry `github.com/mason-org/mason-registry version: 2023-09-05-oily-betta` is installed.

mason.nvim [Core utils] ~
- OK unzip: `UnZip 6.00 of 20 April 2009, by Info-ZIP.  Maintained by C. Spieler.  Send`
- WARNING wget: not available
  - ADVICE:
    - spawn: wget failed with exit code - and signal -. wget is not executable
- OK curl: `curl 8.1.2 (x86_64-apple-darwin22.0) libcurl/8.1.2 (SecureTransport) LibreSSL/3.3.6 zlib/1.2.11 nghttp2/1.51.0`
- OK gzip: `Apple gzip 403.100.6`
- OK tar: `bsdtar 3.5.3 - libarchive 3.5.3 zlib/1.2.11 liblzma/5.0.5 bz2lib/1.0.8 `
- OK bash: `GNU bash, version 3.2.57(1)-release (arm64-apple-darwin22)`
- OK sh: `Ok`

mason.nvim [Languages] ~
- WARNING Go: not available
  - ADVICE:
    - spawn: go failed with exit code - and signal -. go is not executable
- WARNING Composer: not available
  - ADVICE:
    - spawn: composer failed with exit code - and signal -. composer is not executable
- WARNING PHP: not available
  - ADVICE:
    - spawn: php failed with exit code - and signal -. php is not executable
- WARNING cargo: not available
  - ADVICE:
    - spawn: cargo failed with exit code - and signal -. cargo is not executable
- WARNING luarocks: not available
  - ADVICE:
    - spawn: luarocks failed with exit code - and signal -. luarocks is not executable
- WARNING javac: not available
  - ADVICE:
    - spawn: javac failed with exit code 1 and signal 0. The operation couldn’t be completed. Unable to locate a Java Runtime.
      Please visit http://www.java.com for information on installing Java.

- OK node: `v18.17.1`
- WARNING julia: not available
  - ADVICE:
    - spawn: julia failed with exit code - and signal -. julia is not executable
- OK python: `Python 3.11.5`
- WARNING java: not available
  - ADVICE:
    - spawn: java failed with exit code 1 and signal 0. The operation couldn’t be completed. Unable to locate a Java Runtime.
      Please visit http://www.java.com for information on installing Java.

- OK Ruby: `ruby 3.1.3p185 (2022-11-24 revision 1a6b16756e) [arm64-darwin22]`
- OK RubyGem: `3.3.26`
- OK npm: `9.6.7`
- OK pip: `pip 23.2.1 from /opt/homebrew/lib/python3.11/site-packages/pip (python 3.11)`
- OK python venv: `Ok`

mason.nvim [GitHub] ~
- OK GitHub API rate limit. Used: 0. Remaining: 60. Limit: 60. Reset: Tue Sep  5 15:51:34 2023.
  Install and authenticate via gh-cli to increase rate limit.

Screenshots

No response

docwhat commented 11 months ago

I also have macOS and use rbenv.

The only solution I have come up with is to set the "global" ruby version to 3.2.2:

rbenv global 3.2.2

This way, Mason uses that version to install rubocop and solargraph.

zachschultz commented 11 months ago

@docwhat that worked, thank you!

docwhat commented 11 months ago

This isn't a great solution, alas, as it can't take the Gemfile into account to get the right versions, etc.

cmoel commented 6 months ago

I ran into this same issue (on macOS 14.3.1) with this error in the :Mason UI:

   (1) All   (2) LSP   (3) DAP   (4) Linter   (5) Formatter  

  Language Filter: press <C-f> to apply filter

  Failed
    ◍ rubocop
      ▼ Displaying full log
        Installing gem rubocop@1.62.0…
        Successfully installed unicode-display_width-2.5.0
        Successfully installed ruby-progressbar-1.13.0
        Building native extensions. This could take a while...
        ERROR:  Error installing rubocop:
            rubocop-ast requires Ruby version >= 2.7.0. The current ruby version is 2.6.10.210.
        Successfully installed racc-1.7.3
        Successfully installed ast-2.4.2
        Successfully installed parser-3.3.0.5
        [debug] Installation directory retained at "/Users/cmoel/.local/share/nvim/mason/staging/rubocop".
        spawn: gem failed with exit code 1 and signal 0. 

Instead of rbenv global 3.2.2, I navigated to ~/.local and ran rbenv local 3.3.0 and installing rubocop worked:

   (1) All   (2) LSP   (3) DAP   (4) Linter   (5) Formatter  

  Language Filter: press <C-f> to apply filter

  Installed
    ◍ rubocop

Needing to set the ruby version in ~/.local doesn't feel like a great, but it feels like a slight improvement over setting it globally. I'd guess it could be set in ~/.local/share/nvim/mason to be more precise but I haven't tried it yet.

TrevorHinesley commented 1 month ago

None of these work for me fully. Mason fails to update ruby-lsp because it's trying to use the default system version of Ruby (2.6.10.210):

Failed (1)
   ✗ ruby-lsp
       ▼ Displaying full log
           Installing gem ruby-lsp@0.17.9…
           ERROR:  Error installing ruby-lsp:
           sorbet-runtime requires Ruby version >= 2.7.0. The current ruby version is 2.6.10.210.
           spawn: gem failed with exit code 1 and signal 0.

However, prior to this, I had already properly installed ruby-lsp version 0.17.7 under a different Ruby version (3.3.0). Note that I'm in a directory where my current working Ruby version is 3.3.4 using asdf.

Not really sure what's causing that, but the ruby-lsp logs show that the server is working using version 0.17.9 (even though Mason is still "failing to install" under a different Ruby version and showing the package as out of date) now that I manually ran gem install ruby-lsp in the project directory:

. . .   
"/Users/me/.asdf/shims/ruby-lsp"    "stderr"    "Initializing Ruby LSP v0.17.9...\n"
[ERROR][2024-07-23 22:34:27] .../vim/lsp/rpc.lua:770    "rpc"   "/Users/me/.asdf/shims/ruby-lsp"    "stderr"    "Finished initializing Ruby LSP!\n"
[ERROR][2024-07-23 22:34:27] .../vim/lsp/rpc.lua:770    "rpc"   "/Users/me/.asdf/shims/ruby-lsp"    "stderr"    "[Standard Ruby] Activating Standard 
. . .
TrevorHinesley commented 1 month ago

EDIT: @cmoel's actually did work for me (I thought I'd already tried that... guess not). Thank you!

I take it back, that didn't work. Still having issues. I've uninstalled the packages and tried to reinstall with Mason but it still looks like:

rubocop
~                      ▼ Displaying full log
~                        Installing gem rubocop@1.65.1…
~                        Successfully installed unicode-display_width-2.5.0
~                        Successfully installed ruby-progressbar-1.13.0
~                        Building native extensions. This could take a while...
~                        ERROR:  Error installing rubocop:
~                          rubocop-ast requires Ruby version >= 2.7.0. The current ruby version is 2.6.10.210.
~                        Successfully installed racc-1.8.1
~                        Successfully installed ast-2.4.2
~                        Successfully installed parser-3.3.4.0
~                        spawn: gem failed with exit code 1 and signal 0.

standardrb
~                      ▼ Displaying full log
~                        Installing gem standard@1.39.2…
~                        Successfully installed language_server-protocol-3.17.0.3
~                        Building native extensions. This could take a while...
~                        ERROR:  Error installing standard:
~                          rubocop-ast requires Ruby version >= 2.7.0. The current ruby version is 2.6.10.210.
~                        Successfully installed racc-1.8.1
~                        Successfully installed ast-2.4.2
~                        Successfully installed parser-3.3.4.0
~                        spawn: gem failed with exit code 1 and signal 0.

ruby-lsp
~                      ▼ Displaying full log
~                        Installing gem ruby-lsp@0.17.11…
~                        ERROR:  Error installing ruby-lsp:
~                          sorbet-runtime requires Ruby version >= 2.7.0. The current ruby version is 2.6.10.210.
~                        spawn: gem failed with exit code 1 and signal 0.

My ruby version, globally, is 3.3.4, this (I assume) is referring to the default 2.6 Ruby version installed by MacOS that's always there.

TheLonelyGhost commented 1 month ago

I tend to use homebrew for my neovim dependencies and, if you're like me, you may not have noticed that brew install ruby doesn't add the updated ruby interpreter to your system PATH.

From brew info ruby:

``` ... ==> Caveats By default, binaries installed by gem will be placed into: /opt/homebrew/lib/ruby/gems/3.3.0/bin You may want to add this to your PATH. ruby is keg-only, which means it was not symlinked into /opt/homebrew, because macOS already provides this software and installing another version in parallel can cause all kinds of trouble. If you need to have ruby first in your PATH, run: echo 'export PATH="/opt/homebrew/opt/ruby/bin:$PATH"' >> ~/.zshrc For compilers to find ruby you may need to set: export LDFLAGS="-L/opt/homebrew/opt/ruby/lib" export CPPFLAGS="-I/opt/homebrew/opt/ruby/include" ... ```

My Homebrew path is /opt/homebrew, but yours might be /usr/local/homebrew or similar. Adjust accordingly below.

Lua:

vim.fn.setenv('PATH', vim.fn.expand('/opt/homebrew/opt/ruby/bin:$PATH'))

Vimscript:

setenv('PATH', expand('/opt/homebrew/opt/ruby/bin:$PATH'))