rvm system install, bins not properly symlinked

▼魔方 西西 提交于 2019-12-25 02:53:46

问题


I'm on ubuntu 12.04 and installed rvm system wide with:
$ \curl -L https://get.rvm.io | sudo bash -s stable

So far I've always performed single user installs and to he honest I'm quite confused by the results of the system wide install.
It did put the rvm bin directory in my path, but it symlinked all the binaries with names that can't be directly used.
Does it mean that I should symlink them one by one?
Did something go wrong?
Is that the defalt behaviour?

appusr@server-name:/usr/local/rvm/bin$ ll
total 60
drwxrwsr-x  2 root     rvm   4096 Apr  5 13:11 ./
drwxrwsr-x 23 root     rvm   4096 Apr  5 13:04 ../
-rwxrwxr-x  1 root     rvm    578 Apr  5 13:04 bundle*
lrwxrwxrwx  1 appusr   rvm     41 Apr  5 13:11 erb-ruby-2.0.0-p0 -> /usr/local/rvm/wrappers/ruby-2.0.0-p0/erb*
lrwxrwxrwx  1 appusr   rvm     48 Apr  5 13:11 erb-ruby-2.0.0-p0@global -> /usr/local/rvm/wrappers/ruby-2.0.0-p0@global/erb*
lrwxrwxrwx  1 appusr   rvm     41 Apr  5 13:11 gem-ruby-2.0.0-p0 -> /usr/local/rvm/wrappers/ruby-2.0.0-p0/gem*
lrwxrwxrwx  1 appusr   rvm     48 Apr  5 13:11 gem-ruby-2.0.0-p0@global -> /usr/local/rvm/wrappers/ruby-2.0.0-p0@global/gem*
lrwxrwxrwx  1 appusr   rvm     41 Apr  5 13:11 irb-ruby-2.0.0-p0 -> /usr/local/rvm/wrappers/ruby-2.0.0-p0/irb*
lrwxrwxrwx  1 appusr   rvm     48 Apr  5 13:11 irb-ruby-2.0.0-p0@global -> /usr/local/rvm/wrappers/ruby-2.0.0-p0@global/irb*
-rwxrwxr-x  1 root     rvm    556 Apr  5 13:04 rake*
lrwxrwxrwx  1 appusr   rvm     42 Apr  5 13:11 rake-ruby-2.0.0-p0 -> /usr/local/rvm/wrappers/ruby-2.0.0-p0/rake*
lrwxrwxrwx  1 appusr   rvm     49 Apr  5 13:11 rake-ruby-2.0.0-p0@global -> /usr/local/rvm/wrappers/ruby-2.0.0-p0@global/rake*
lrwxrwxrwx  1 appusr   rvm     42 Apr  5 13:11 rdoc-ruby-2.0.0-p0 -> /usr/local/rvm/wrappers/ruby-2.0.0-p0/rdoc*
lrwxrwxrwx  1 appusr   rvm     49 Apr  5 13:11 rdoc-ruby-2.0.0-p0@global -> /usr/local/rvm/wrappers/ruby-2.0.0-p0@global/rdoc*
lrwxrwxrwx  1 appusr   rvm     40 Apr  5 13:11 ri-ruby-2.0.0-p0 -> /usr/local/rvm/wrappers/ruby-2.0.0-p0/ri*
lrwxrwxrwx  1 appusr   rvm     47 Apr  5 13:11 ri-ruby-2.0.0-p0@global -> /usr/local/rvm/wrappers/ruby-2.0.0-p0@global/ri*
lrwxrwxrwx  1 appusr   rvm     42 Apr  5 13:11 ruby-2.0.0-p0 -> /usr/local/rvm/wrappers/ruby-2.0.0-p0/ruby*
lrwxrwxrwx  1 appusr   rvm     49 Apr  5 13:11 ruby-2.0.0-p0@global -> /usr/local/rvm/wrappers/ruby-2.0.0-p0@global/ruby*
-rwxrwxr-x  1 root     rvm   1307 Apr  5 13:04 rvm*
-rwxrwxr-x  1 root     rvm   1512 Apr  5 13:04 rvm-auto-ruby*
-rwxrwxr-x  1 root     rvm   1803 Apr  5 13:04 rvm-exec*
-rwxrwxr-x  1 root     rvm  13130 Apr  5 13:04 rvm-installer*
-rwxrwxr-x  1 root     rvm   3850 Apr  5 13:04 rvm-prompt*
-rwxrwxr-x  1 root     rvm   2263 Apr  5 13:04 rvm-shell*
-rwxrwxr-x  1 root     rvm    648 Apr  5 13:04 rvm-smile*
-rwxrwxr-x  1 root     rvm   2229 Apr  5 13:04 rvmsudo*
lrwxrwxrwx  1 appusr   rvm     44 Apr  5 13:11 testrb-ruby-2.0.0-p0 -> /usr/local/rvm/wrappers/ruby-2.0.0-p0/testrb*
lrwxrwxrwx  1 appusr   rvm     51 Apr  5 13:11 testrb-ruby-2.0.0-p0@global -> /usr/local/rvm/wrappers/ruby-2.0.0-p0@global/testrb*
appusr@server-name:/usr/local/rvm/bin$ 
appusr@server-name:/usr/local/rvm/bin$ 
appusr@server-name:/usr/local/rvm/bin$ 
appusr@server-name:/usr/local/rvm/bin$ which ruby
appusr@server-name:/usr/local/rvm/bin$ which irb
appusr@server-name:/usr/local/rvm/bin$ which gem
appusr@server-name:/usr/local/rvm/bin$ /usr/bin/env ruby -v
/usr/bin/env: ruby: No such file or directory
appusr@server-name:/usr/local/rvm/bin$ ruby -v
The program 'ruby' can be found in the following packages:
 * ruby1.8
 * ruby1.9.1
Ask your administrator to install one of them
appusr@server-name:/usr/local/rvm/bin$

回答1:


you should check /usr/local/rvm/wrappers especially /usr/local/rvm/wrappers/default for binaries that can be used from PATH with no other settings in environment.




回答2:


I believe I found what was wrong. Apparently rvm wasn't properly loaded as a function, that is
$ type rvm | head -n 1
didn't return "rvm is a function", but something like "rvm is hashed" (...?...).

It is also interesting that the problem wasn't limited to the system wide install. I imploded the system wide rvm install, removed the references in /etc, and installed it again without sudo... same problem.

I'd say it was my fault, and by "my" I mean that I wasn't aware of how bash handles some user switches. It may be useful to others as well, so I'll report what I did.

I had ssh'd into the server as a general user and then switched to the user who will run the rails stack: su appusr (using bash).

After that, I installed rvm using:
$ \curl -L https://get.rvm.io | bash -s stable


When I tried the system wide install I of course also added the user to the rvm group with:
$ sudo usermod -a -G rvm appusr


...and logged out and in again: exit, and again su appusr.

Now, it seems that by doing so bash was only sourcing ~/.bashrc, and not ~/.bash_profile where rvm had placed the statement to load rvm as a function:
[[ -s "$HOME/.rvm/scripts/rvm" ]] && source "$HOME/.rvm/scripts/rvm"

Still, the rvm binary was in my PATH, and I could issue the commands needed to install ruby.
So far, so good.
The problem was that after the installation it somehow failed to select the only ruby I had installed as the default interpreter, and so it didn't create the symlinks.

I noticed it because when I issued rvm list I was presented with:

rvm rubies

   ruby-2.0.0-p0 [ x86_64 ]

# => - current
# =* - current && default
#  * - default

... notice how it was NOT marked with =*.
I used the command rvm use ruby-2.0.0-p0 --default, and I was warned that rvm wasn't loaded as a function and that something could not work (can't rememeber the exact message).

That was a breakthrough, and as I sourced ~/.bash_profile I could successfully select that ruby and all the symlinks (ruby, irb, rake, etc) were immediately created.

That wasn't ideal, though.
The default setup of my $HOME folder has the usual three files: ~/.profile, ~/.bash_profile and ~/.bashrc (plus the ones for zsh).
~/.bash_profile was added by the rvm installation, and I'm having it source ~/.profile.
~/.profile, then, automatically sources ~/.bashrc if bash is being used.

As I said, however, by doing su appusr bash just sources ~/.bashrc, and so fails to parse the statement loading rvm as a function. Very annoying.
Telling ~/.bashrc to source ~/.bash_profile would need some sort of control (an ENV variable?) to avoid an infinite reference loop, and seemed overkilling...
So I just moved [[ -s "$HOME/.rvm/scripts/rvm" ]] && source "$HOME/.rvm/scripts/rvm" into ~/.bashrc, and I'd say everything seems to work now.



来源:https://stackoverflow.com/questions/15835329/rvm-system-install-bins-not-properly-symlinked

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!