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

rbenv: cannot rehash: /usr/local/var/rbenv/shims/.rbenv-shim exists #759

Closed
drew-kun opened this issue Jul 24, 2015 · 10 comments
Closed

rbenv: cannot rehash: /usr/local/var/rbenv/shims/.rbenv-shim exists #759

drew-kun opened this issue Jul 24, 2015 · 10 comments

Comments

@drew-kun
Copy link

@drew-kun drew-kun commented Jul 24, 2015

Hi! When trying to $ rbenv rehash getting:

rbenv: cannot rehash: /usr/local/var/rbenv/shims/.rbenv-shim exists

What does that mean?

@mislav
Copy link
Member

@mislav mislav commented Jul 24, 2015

During the rehash process, rbenv writes out the temporary file .rbenv-shim to indicate that the rehash is in progress. Then, if a parallel rbenv rehash process tries to run at the same time, it will fail because the file already exists. This guards against race conditions in parallel rehashes.

It doesn't sound like you're running multiple rbenv rehash processes in parallel, though. It seems like .rbenv-shim file was never cleaned up after a rehash that ran earlier. That earlier process might have been killed prematurely and never cleaned up after itself.

Solution: remove the file and try again.

@igorshtopor
Copy link

@igorshtopor igorshtopor commented Sep 10, 2015

@mislav

That earlier process might have been killed prematurely and never cleaned up after itself.

I'm wondering what can be the root cause for such scenario?

@mislav
Copy link
Member

@mislav mislav commented Sep 10, 2015

@shyjt I don't know! Maybe if you run rbenv rehash but Ctrl-C it before it finishes.

@drew-kun
Copy link
Author

@drew-kun drew-kun commented Sep 11, 2015

That was so weird - I've reinstalled the package and it didn't help… But when I've repeated the procedure after restart it solved this problem and never happened again…

@trejkaz
Copy link

@trejkaz trejkaz commented Jun 16, 2016

I had this same error message on multiple servers on the same day, and in all cases deleting the file made it work again the next time.

If this is a kind of pseudo-lock file, perhaps what rbenv could do is open and actually lock the file. Then a second rbenv which comes along and sees the file could simply try to delete it before recreating it.

@glebm
Copy link

@glebm glebm commented Mar 2, 2017

This has failed for me just now on an Ubuntu 16.04 server:

Relevant Ansible output:

TASK [deploy-rails : Ensure ruby 2.4.0 is installed] *******************************************
fatal: [prod1]: FAILED! => {
  "cmd": "cd; bash -lc 'MAKEOPTS=\"-j $(getconf _NPROCESSORS_ONLN)\" CONFIGURE_OPTS=\"--disable-install-rdoc\" rbenv install 2.4.0'",
  "rc": 1,
  "stderr_lines": [
    "Downloading ruby-2.4.0.tar.bz2...",
    "-> https://cache.ruby-lang.org/pub/ruby/2.4/ruby-2.4.0.tar.bz2",
    "Installing ruby-2.4.0...",
    "Installed ruby-2.4.0 to /home/plforums/.rbenv/versions/2.4.0",
    "",
    "rbenv: cannot rehash: /home/plforums/.rbenv/shims/.rbenv-shim exists"
  ],
  "stdout_lines": []
}

No other commands were run in parallel. Both rbenv and ruby-build are from master as of 5 minutes ago.

After SSH'ing into the server and running rbenv uninstall 2.4.0, re-running the playbook has succeeded.

This does not seem like a user error. Seems to be a race condition in rbenv or ruby-build.

@MartinNowak
Copy link
Contributor

@MartinNowak MartinNowak commented Mar 26, 2017

I'm getting a similar error, not b/c the lock file gets clobbered, but b/c of the 2>/dev/null redirect, which according to bash clobbers /dev/null.

Just test bash.

set -o noclobber
echo >/dev/null

bash --version

GNU bash, version 4.3.11(1)-release (x86_64-pc-linux-gnu)
Copyright (C) 2013 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>

This is free software; you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.

That redirections needs to be done explicity, see Safe I/O Redirection with noclobber (Unix Power Tools, 3rd Edition).

@mislav mislav closed this in db39044 Nov 29, 2017
mislav added a commit that referenced this issue Nov 29, 2017
partly resolve #759
jrolfs added a commit to jrolfs/rbenv that referenced this issue Nov 30, 2017
- some versions of bash (e.g. 4.3.11) complain about clobbering
  /dev/null, use bash's explicit >| operator to ignore noclober
- not sure if the original rbenv#759 report has the same cause
- rbenv#759 (comment)
@jakesyl
Copy link

@jakesyl jakesyl commented Jan 22, 2018

Any update on this? I still have this issue. I guess I'll check out #982 which reports to fix.

@meowsus
Copy link

@meowsus meowsus commented Aug 10, 2018

Makes me wonder how long my system has thought a rehash was already in progress O_o

@saulwiggin
Copy link

@saulwiggin saulwiggin commented Feb 18, 2020

I ran rbenv doctor with the command

curl -fsSL https://github.com/rbenv/rbenv-installer/raw/master/bin/rbenv-doctor | bash

and then was told this

Checking for rbenv' in PATH: /usr/local/bin/rbenv Checking for rbenv shims in PATH: not found The directory /Users/user/.rbenv/shims' must be present in PATH for rbenv to work.
Please run `rbenv init' and follow the instructions.

Checking `rbenv install' support: /usr/local/bin/rbenv-install (ruby-build 20200214)

and it worked after exporting this director to the path like this

export PATH="$PATH:/Users/user/.rbenv/shims"

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
10 participants
You can’t perform that action at this time.