2

I have recently installed rbenv for some ruby projects but now cannot run my reactjs server for a different project.

The error message from running yarn start is rbenv: yarn: command not found

According to this link the error may have something to do with the shims. So I ran the below code in the terminal:

for ver in $(rbenv whence yarn); do
  RBENV_VERSION="$ver" gem uninstall -ax yarn
  rm -f "$(rbenv prefix "$ver")/bin/yarn"
done
rbenv rehash

# now check the yarn executable again:
which -a yarn

when running which -a yarn I get:

/home/user/.rbenv/shims/yarn
/home/user/.rbenv/shims/yarn
/home/user/.nvm/versions/node/v14.8.0/bin/yarn
/home/user/.rbenv/shims/yarn
/home/user/.rbenv/shims/yarn
/usr/bin/yarn
/bin/yarn

Clearly I'm missing something here

jonrsharpe
  • 115,751
  • 26
  • 228
  • 437
avoshmo
  • 55
  • 5

2 Answers2

2

That code from the thread that you linked to will remove the yarn shim from any versions of Ruby that you may have installed with rbenv that have it. However, some versions of Rails (maybe other Ruby projects too?) also have a yarn shim inside their bin/ directory. The presence of this shim causes a yarn shim to be added to ~/rbenv/shims/ each time rbenv rehash is called to regenerate your binstubs. The rbenv rehash command can be called automatically each time your shell environment is loaded too if your environment was setup with rbenv to do this with eval "$(rbenv init -)". The shim inside ~/rbenv/shims/ is what causes this rbenv: yarn: command not found error globally whenever you invoke yarn.

If you move the shim inside your project from bin/ to .bundle/bin/, then run rbenv rehash, that should fix the issue. If you have yarn installed globally then you could also consider removing the shim from your project altogether, since all it does is call yarn for you and give you an error if it's not installed.

Adam
  • 1,755
  • 20
  • 31
1

Besides uninstalling the yarn gem from all your rbenv versions, you also need to change the binstubs paths for all your rails projects (and any other rbenv-managed project using bundler).

First, run this to see which projects rbenv-binstubs is looking for shimmable executables: cat "$(rbenv root)/bundles"

cd into each of those directories and run bundle install --binstubs .bundle/bin to set the binstubs path.

Kelvin
  • 20,119
  • 3
  • 60
  • 68