bash: /usr/bin/ruby: No such file or directory - ruby

I am trying to run a ruby program and I get bash: /usr/bin/ruby: No such file or directory When I navigate to /usr/bin/ruby and ls | grep ruby I get an output with ruby in it. When I try to ./ruby I STILL get bash: ./ruby: No such file or directory. I have tried uninstalling and reinstalling ruby to no avail.
Does anyone have any idea what could be going on? I am really stumped.

Just adding a different possible cause and fix for the same /usr/bin/ruby: No such file or directory error after installing Ruby.
If, unlike the original poster here, you get this same message but on investigating find that there really is nothing at /usr/bin/ruby, try /usr/local/bin/ruby --version: it seems that some installations put the binary in /usr/local/bin/ruby but look for it at /usr/bin/ruby.
This happened to me with ruby version 1.9.3p547 on Centos. If this is what's happened, the easy fix is to create a symlink at /usr/bin/ruby that points to /usr/local/bin/ruby.

Per the comments on the question, your /usr/bin/ruby binary is a symlink to /etc/alternatives/ruby.
lrwxrwxrwx 1 root root 22 Aug 12 20:11 /usr/bin/ruby -> /etc/alternatives/ruby
You should confirm that path exists (run ls -la /etc/alternatives/ruby to check if that path exists) and if it does not, you'll need to reinstall Ruby using your system package manager (e.g., apt-get), download and install Ruby from https://www.ruby-lang.org, or use a tool like RVM.

The better option is use
#!/usr/bin/env ruby
it will always use current selected ruby in the environment, not depending on any tool

I had this error while working on Ruby on rails project and deployment to heroku.
For ruby on rails and heroku
On you editor, find 'bin' folder then in each file remove the ruby number extension leaving 'ruby' only on the commented code.
Thank me later

Related

Gem "Malformed Version Number String"

I'm building a gem. I just got the basic project structure laid out, and I tried building it with gem build my_gem.gemspec, which worked fine. Then I installed it with gem install My\ Gem-0.0.1.gem and it still looked like it worked fine. Then I tried to run irb and I got this:
/Users//.rbenv/versions/2.2.2/lib/ruby/2.2.0/rubygems/version.rb:206:in `initialize': Malformed version number string on (ArgumentError)
I tried making some changes and saved them. I ran gem build my_gem.gemspec. Same error.
All irb, rails, and gem sub-commands are generating a stack trace with this at the top. What did I do to break all of these commands and how do I reverse it?
You should manually delete your gem:
cd $GEM_HOME
find . -path \*my_gem\*
If everything looks good (i.e. there are no files which aren't related to your gem):
find . -path \*my_gem\* -delete
Before installing your gem again, make sure you specified version in your .gemspec.
UPD.
Other locations to look for the residue of the gem:
~/.rvm/gems/ruby-<version>#global
~/.rvm/gems/ruby-<version>
/System/Library/Frameworks/Ruby.framework/
# look for "GEM PATHS" section
gem env
# rbenv paths
~/.rbenv/versions
~/.gem/
UPD2
Problem solved! Steps taken:
This showed where exactly is this particular Rubygems executable, which failed to load:
rbenv which gem
# => /Users/<username>/.rbenv/versions/2.2.2/bin/gem
Then it turns out under 2.2.2 directory there were cache, doc and specifications directories, all of which contained a file or sub-directory with the residue of the broken gem. Deleting them all solved the problem.
(2016-May-24)
I solve this problem today.
I was try to learn how to write a gem. and then cause this problem.
My guess is because my gem's name contain whitespace: "hola 1c7"
and gem do not tell you how to solve this prbolem, this is annoying
you should go to:
/usr/local/lib/ruby/gems/2.3.0/specifications
delete that xxx.gemspec
in my case, my gem's name is "hola 1c7"
so I delete "hola 1c7-0.1.2.gemspec"
I think is the space cause problem.
if this not working,
try to search your gems name in /usr/local/lib/ruby/gems/
and delete all the file you can find,
in my case, first I delete
hola 1c7.1.3.2.gem from /usr/local/lib/ruby/gems/2.3.0/cache
so the command is :
/usr/local/lib/ruby/gems/2.3.0/cache$ sudo rm -rf hola\ 1c7-1.3.2.gem
and then
/usr/local/lib/ruby/gems/2.3.0/gems$ sudo rm -rf hola\ 1c7-1.3.2/
My Ruby Version : Ruby 2.3.0
My Linux Version : Ubuntu 16.04 LTS
I couldn't find the files in the reference path, or some of the other suggested paths in this post. Some thing that helped me was to first comment out the error be raised in the version.rb file on line 201. Then use the GEM PATH directory using $ gem env to find the path that had references to the gem. Make sure to remove everything from the doc, cache, and specifications folders. This finally solved my issue.

Problem with Vim's Ruby plugin

I have just installed Vim and when ever I go to open in ruby file I get these errors:
Error detected while processing C:\Program files (x86)\Vim\vimfiles\ftplugin\ruby.vim
line: 76
Encoding::ConverterNotFoundError: code converter not found (UTF-16LE to ASCII-8bit)
line: 93
E121 :Undefined varaible: s:ruby_path
E15: Invalid expression: s:ruby_path
line: 76
NameError: uninitialized constant Gem::Quickloader
line: 93
I have Ruby 192 installed and I get this error even if I update ruby vim files.
These are the two lines those errors are referring to if it helps:
line 76: ruby VIM::command( 'let s:ruby_path = "%s"' % ($: + begin; require %q{rubygems}; Gem.all_load_paths.sort.uniq; rescue LoadError; []; end).join(%q{,}) )
line 93: let &l:path = s:ruby_path
Note that instead of editing ruby.vim file you can just add
let g:ruby_path = ':C:\ruby192\bin'
in your _vimrc file (or equivalent for your platform). That way you won't need to keep re-editing ruby.vim when you update it.
If you run RVM and want its default ruby, use:
let g:ruby_path = "/Users/allen/.rvm/rubies/default/bin"
If you set your ruby interpreter in your project .rvmrc file, you can create an environment variable in your .rvmrc:
rvm 1.9.2#projectname --create
export RUBY_BIN=`which ruby | sed 's/ruby$//'`
You can use environment variables in your .vimrc:
let g:ruby_path=$RUBY_BIN
(Note you should also set a default $RUBY_BIN in your .bashrc or .zshrc so this works outside of .rvmrc projects.)
If your ~/.rvm/rubies/default/bin path does not yet exist, you need to set your rvm system default of ruby. At your command prompt or terminal application, enter:
rvm use 1.9.2 --default
using whatever ruby version you need.
How did you install Ruby?
Go into irb and enter:
Gem.all_load_paths.uniq
which should return a list of paths to your install gems that Gem knows about also.
That's what is failing in your error message and leads me to suspect you are missing some path or environment info, because it looks like vim isn't able to find your Ruby gems correctly.
Encoding::ConverterNotFoundError is a core library exception, so that part is working, but it looks like the Gem command isn't working.
Your problem is probably Ruby 1.9 - AFAIK Vim only works with Ruby 1.8, so you might have to downgrade your Ruby version to get Vim working.
I opened the file "C:...\vim73\ftplugin\ruby.vim" and right before line 73 or so, where the code reads:
if !exists("s:ruby_path")
I added:
let s:ruby_path = 'C:\ruby192\bin'
So far vim seems happier about editing ruby files. Note I installed my ruby in the "C:" directory instead of "Program Files" to get a better pathname to ruby.exe.
My version of ruby.vim is dated 2010 Mar 15.
Updating to the latest release of Ruby 1.9.2 (1.9.2p180 (2011-02-18) at the time of posting) fixed this for me.
I was running 1.9.2p132 or so when I had the problem, which seems to have been patched around Dec 2010. You can check your current version by running ruby -v.

-bash is messed up?

Trying to figure out why I could not set up Heroku Gem and following this answer SO 2396004 (Heroku Gem Doesn't Work). I think I might have messed up my system.
Now I am typing heroku list and I get (-bash: heroku: command not found) and when I type in ruby -v I get (-bash: ruby: command not found)
BELOW IS THE MOST RECENT OUTPUT
zak$ export PATH=$PATHEXECUTABLE DIRECTORY: /Users/zak/.rvm/gems/ruby-1.9.2-p0#rails3tutorial/bin
-bash: export: `DIRECTORY:': not a valid identifier
-bash: export: `/Users/zak/.rvm/gems/ruby-1.9.2-p0#rails3tutorial/bin': not a valid identifier
ZKidds-MacBook-Pro:rails_projects zak$ export PATH=$PATH:/Users/zak/.rvm/gems/ruby-1.9.2-p0#rails3tutorial/bin
ZKidds-MacBook-Pro:rails_projects zak$ heroku list
-bash: heroku: command not found
ZKidds-MacBook-Pro:rails_projects zak$ cd ..
ZKidds-MacBook-Pro:~ zak$ export PATH=$PATH:/Users/zak/.rvm/gems/ruby-1.9.2-p0#rails3tutorial/bin
ZKidds-MacBook-Pro:~ zak$ heroku list
-bash: heroku: command not found
ZKidds-MacBook-Pro:~ zak$ echo $PATH
:/Users/zak/.rvm/gems/ruby-1.9.2-p0#rails3tutorial/bin:/Users/zak/.rvm/gems/ruby-1.9.2-p0#rails3tutorial/bin
-bash: GEM: command not found
ZKidds-MacBook-Pro:~ zak$ gem env
-bash: gem: command not found
ZKidds-MacBook-Pro:~ zak$ heroko list
-bash: heroko: command not found
When you set PATH to just one value, you lost all the other places to search, such as /bin and /usr/bin. Set your PATH incrementally:
export PATH=/new/place/bin:$PATH
You can be more elaborate than that, but that basic technique works.
Meantime, logout and login again - that will get you going most easily. Alternatively:
export PATH=$PATH:/bin:/usr/bin
Additionally, your first line was:
export PATH=$PATHEXECUTABLE DIRECTORY: /Users/zak/.rvm/gems/ruby-1.9.2-p0#rails3tutorial/bin
When you run export, it will export one or more variables, but the values must either be simple variable names, or must be variable assignments:
export SOMEVAR NOTHERVAR=new-value ...
The complaint -bash: export:DIRECTORY:': not a valid identifier` is telling you that 'DIRECTORY:' is not valid. It is not clear what you had in mind. And you got a similar complaint about /Users/zak/... not being an identifier.
You can set an environment variable for just one run of a command:
PATH=$EXECUTABLE_DIRECTORY:$PATH /Users/zak/bin/command
The environment of the command will include the value of PATH given; note, though, that the shell won't search for the command with that modified path.
...What I was trying to do was...
I'm not a user of either Ruby or Rails, but on my Mac (10.6.4), I can find:
Osiris-2 JL: ruby -v
ruby 1.8.7 (2009-06-12 patchlevel 174) [universal-darwin10.0]
Osiris-2 JL: rails -v
Rails 2.3.5
Osiris-2 JL: which ruby rails
/usr/bin/ruby
/usr/bin/rails
Osiris-2 JL:
So, on my machine, both Ruby and Rails are in /usr/bin. I don't have Heroku installed AFAIK (not on my PATH, anyway). Your first export clobbered PATH; the second one added your Ruby 1.9.2 directory to the empty PATH. Apparently, Heroku is installed somewhere else, or is not yet installed at all. You changed directory - a built-in operation that does not require a working PATH; you added the Ruby 1.9.2 directory to your PATH again (which didn't change anything usefully). Heroku is still not found. You echoed PATH (another built-in) - I'm not clear where the GEM: command not found message comes from. And the commands gem and heroko (sic) were not found. So, your first command set in train the problems.
Then you commented:
In terms of what I was trying to do, I was just trying to set-up my heroku account and got stuck when I tried to add my public ssh key. The heroko gem I had installed (thought) was not registering. That is when I read through the stackoverflow question referenced above that suggested my path was incorrect. I closed terminal and reopened. Running stuff like ruby -v outputs, but running rails -v does not. Is there something still to do? Why would rails -v not output?
Specifically on rails -v I get "/System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/1.8/rubygems.rb:827:in report_activate_error': Could not find RubyGem rails (>= 0) (Gem::LoadError) from /System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/1.8/rubygems.rb:261:inactivate' from /System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/1.8/rubygems.rb:68:in `gem' from /usr/bin/rails:18 "
This suggests that you have rails installed in /usr/bin (like I do), but the installation has been altered somehow so it is self-inconsistent. Either that or the messed up environment (PATH) is causing trouble. But usually, software can find its own bits'n'pieces, so it suggests there is something up. Part of the trouble may be that you're using a Ruby 1.9.2 program with some Ruby 1.8 software.
My personal policy is to leave o/s provided software strictly alone; I let the Mac updates take care of that. If I want my own version of something, I build it and install it under my control - I do this with Perl, sometimes with GCC, and with Git or SVN or Mercurial or other such software.
I would look at ensuring you have the Ruby 1.9.2 environment working fully, and worry about whether you need to update your Rails environment in parallel. I suspect that using Ruby 1.9.2 with Rails built for Ruby 1.8.x is causing some of the trouble - but I'm not certain of that.
The fact I think is you misunderstand the doc you are reading.
When you read "$PATHEXECUTABLE DIRECTORY" it's a placeholder to be substituate with the real path of what you want to add.
To do it properly, follow what Jonathan Leffler said.

How to tell Terminal which version of Ruby to use?

I have two related questions that I was hoping someone could help out with.
I recently installed Ruby 1.9.2 on my Mac (running Snow Leopard 10.6.4) and I haven’t been able to figure out how to get Terminal to use the new Ruby as a default, rather than the factory-installed Ruby 1.8.7. The old Ruby 1.8.7 is located in my ~/usr/bin/ruby directory while the new Ruby 1.9.2 is in ~/usr/local/bin/ruby. Someone said that I need to put the new version of Ruby's directory in the PATH prior to the old version's directory so that the system looks there first - is this correct? If so, can anyone provide step by step instructions on how to do this?
I’ve created a new directory but can’t seem to figure out the correct way to add that directory to my PATH using the Terminal bash shell. I tried using the instructions that I found here (http://www.macgasm.net/2008/04/10/ad...thin-terminal/) twice but they didn't work for me. The directory containing my program ("Ruby_Programs") shows up in the PATH but when I try to run "ruby newprogram.rb" from the command line it results in ":ruby: No such file or directory -- newprogram.rb (LoadError)". The file definitely exists and is a functional Ruby program. I did change the name of the directory to "Ruby Programs" and then back to "Ruby_Programs" - could that have somehow caused this problem?
Any help would be greatly appreciated. Here is my current PATH:
$ echo $PATH
/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin:/Users/sbrriffe/src:/usr/X11/bin:/Users/sbriffe/Ruby_Programs/:
You might want to check out rvm. You can install multiple versions of ruby side by side and easily switch between them. If you follow the rvm installation notes you won't have any more path problems.
Your Ruby Programs directory shouldn't be in your path: the location of your ruby interpreter should be. Then, you cd to the location of your ruby program, and run it from there: ruby program.rb.
Since you are on a Mac, check out homebrew for something that will make installing software easier. I have my homebrew set up in /usr/local, and it works great.
Once you have installed stuff where you need it, then you'll want to adjust your $PATH. The items in $PATH are searched in the order they appear, so in your ~/.bashrc, you'll want to add:
export PATH=/usr/local/bin:$PATH
To make sure /usr/local/bin gets searched before /usr/bin.
I would use RVM to get everything installed, and then once you have RVM installed it is easy to set your default Ruby version.
Check out https://rvm.io/ -- once you have that installed you can change your default by using : $ rvm use 1.9.2 --default
hope that helps- you can do this with any version, not only 1.9.2

cannot install ruby gems - zlib error

I'm trying to install some Ruby Gems so I can use Ruby to notify me when I get twitter messages. However, after doing a gem update --system, I now get a zlib error every time I try and do a gem install of anything. below is the console output I get when trying to install ruby gems. (along with the output from gem environment).
C:\data\ruby>gem install twitter
ERROR: While executing gem ... (Zlib::BufError)
buffer error
C:\data\ruby>gem update --system
Updating RubyGems
ERROR: While executing gem ... (Zlib::BufError)
buffer error
C:\data\ruby>gem environment
RubyGems Environment:
- RUBYGEMS VERSION: 1.2.0
- RUBY VERSION: 1.8.6 (2007-03-13 patchlevel 0) [i386-mswin32]
- INSTALLATION DIRECTORY: c:/ruby/lib/ruby/gems/1.8
- RUBY EXECUTABLE: c:/ruby/bin/ruby.exe
- EXECUTABLE DIRECTORY: c:/ruby/bin
- RUBYGEMS PLATFORMS:
- ruby
- x86-mswin32-60
- GEM PATHS:
- c:/ruby/lib/ruby/gems/1.8
- GEM CONFIGURATION:
- :update_sources => true
- :verbose => true
- :benchmark => false
- :backtrace => false
- :bulk_threshold => 1000
- REMOTE SOURCES:
- http://gems.rubyforge.org/
Found it! I had the same problem on windows (it appeared suddenly without me doing an update, but whatever):
It has something to do with multiple conflicting zlib versions (I think).
In ruby/lib/ruby/1.8/i386-msvcrt, make sure that there exists a zlib.so file. In my case, it was already there. If not, you may try to install ruby-zlib.
Then go to ruby/lib/ruby/site_ruby/1.8./i386-msvcrt and delete the zlib.so file there.
In ruby/bin, there should be a zlib1.dll. For some reason my Ruby version did not use this dll. I downloaded the most recent version (1.2.3) and installed it there. I had to rename it to zlib.dll for it to be used.
And tada! Rubygems worked again.
Hope this helps.
Firstly, I thank the person, who came up with the solution to the missing zlib problem. (It wasn't me. :-)
Unfortunately I lost the link to the original posting, but the essence of the solution on Linux is to compile the Ruby while zlib header files are available to the Ruby configure script. On Debian it means that zlib development packages have to be installed before one starts to compile the Ruby.
The rest of my text here does not contain anything new and it is encouraged to omit it, if You feel comfortable at customizing Your execution environment at UNIX-like operating systems. The following is a combination of a brief intro to some basics and step by step instructions.
------The-start-of-the-HOW-TO-------------------------
If one wants to execute a program, let's say, irb, from a console, then the file named irb is searched from folders in an order that is described by an environment variable called PATH. It's possible to see the value of the PATH by typing to a bash shell (and pressing Enter key):
echo $PATH
For example, if there are 2 versions of irb in the system, one installed by the "official" package management system, let's say, yum or apt-get, to /usr/bin/irb and the other one that is compiled by the user named scoobydoo and resides in /home/scoobydoo/ourcompiledruby/bin then the question arises, which one of the two irb-s gets executed.
If one writes to the
/home/scoobydoo/.bashrc
a line like:
export PATH="/home/scoobydoo/ourcompiledruby/bin:/usr/bin"
and restarts the bash shell by closing the terminal window and opening a new one, then by typing irb to the console, the
/home/scoobydoo/ourcompiledruby/bin/irb gets executed. If one wrote
export PATH="/usr/bin:/home/scoobydoo/ourcompiledruby/bin"
to the
/home/scoobydoo/.bashrc
,then the /usr/bin/irb would get executed.
In practice one wants to write
export PATH="/home/scoobydoo/ourcompiledruby/bin:$PATH"
because this prepends all of the values that the PATH had prior to this assignment to the /home/scoobydoo/ourcompiledruby/bin. Otherwise there will be problems, because not all common tools reside in the /usr/bin and one probably wants to have multiple custom-built applications in use.
The same logic applies to libraries, except that the name of the environment variable is LD_LIBRARY_PATH
The use of the LD_LIBRARY_PATH and PATH allow ordinary users, who do not have root access or who want to experiment with not-that-trusted software, to build them and use them without needing any root privileges.
The rest of this mini-how-to assumes that we'll be building our own version of ruby and use our own version of it almost regardless of what is installed on the system by the distribution's official package management software.
1)=============================
First, one creates a few folders and set the environment variables, so that the folders are "useful".
mkdir /home/scoobydoo/ourcompiledruby
mkdir -p /home/scoobydoo/lib/our_gems
One adds the following 2 lines to the
/home/scoobydoo/.bashrc
export PATH="/home/scoobydoo/ourcompiledruby/bin:$PATH"
export GEM_HOME="/home/scoobydoo/lib/our_gems"
Restart the bash shell by closing the current terminal window and opening a new one or by typing
bash
on the command line of the currently open window.
The changes to the /home/scoobydoo/.bashrc do not have any effect on terminal windows/sessions that were started prior to the saving of the modified version of the /home/scoobydoo/.bashrc
The idea is that the /home/scoobydoo/.bashrc is executed automatically at the start of a session, even if one logs on over ssh.
2)=============================
Now one makes sure that the zlib development packages are available on the system. As of April 2011 I haven't sorted the details of it out, but
apt-get install zlibc zlib1g-dev zlib1g
seems to be sufficient on a Debian system. The idea is that both, the library file and header files, are available in the system's "official" search path. Usually apt-get and alike place the header files to the /usr/include and library files to the /usr/lib
3)=============================
Download and unpack the source tar.gz from the http://www.ruby-lang.org
./configure --prefix=/home/scoobydoo/ourcompiledruby
make
make install
4)=============================
If a console command like
which ruby
prints to the console
/home/scoobydoo/ourcompiledruby/bin/ruby
then the newly compiled version is the one that gets executed on the command
ruby --help
5)=============================
The rest of the programs, gem, irb, etc., can be properly executed by using commands like:
ruby `which gem` install rake
ruby `which irb`
It shouldn't be like that but as of April 2011 I haven't figured out any more elegant ways of doing it. If the
ruby `which gem` install rake
gives the zlib missing error again, then one should just try to figure out, how to make the zlib include files and library available to the Ruby configure script and recompile. (Sorry, currently I don't have a better solution to offer.)
May be a dirty solution might be to add the following lines to the
/home/scoobydoo/.bashrc
alias gem="`which ruby` `which gem` "
alias irb="`which ruby` `which irb` "
Actually, I usually use
alias irb="`which ruby` -KU "
but the gem should be executed without giving the ruby the "-KU" args, because otherwise there will be errors.
------The-end-of-the-HOW-TO------------------------
I just started getting this tonight as well. Googling turned up a bunch of suggestions that didn't deliver results
gem update --system
and some paste in code from jamis that is supposed to replace a function in package.rb but the original it is supposed to replace is nowhere to be found.
Reinstalling rubygems didn't help. I'm reinstalling ruby right now.........and it is fixed. Pain though.
How about cd into rubysrc/ext/zlib, then ruby extendconf.rb, then make, make install.
After do that, reinstall ruby.
I did this on ubuntu 10.04 and was successful.
A reinstall of Ruby sorted this issue out. It's not what I wanted; I wanted to know why I was getting the issue, but it's all sorted out.
It most often shows up when your download failed -- i.e. you have a corrupt gem, due to network timeout, faulty manual download, or whatever. Just try again, or download gems manually and point gem at the files.
if gem update --system not works and rename ruby/bin/zlib1.dll to zlib.dll not helps try:
Open file RUBY_DIR\lib\ruby\site_ruby\1.8\rubygems.rb
And replace existed def self.gunzip(data) by this:
def self.gunzip(data)
require 'stringio'
require 'zlib'
data = StringIO.new data
# Zlib::GzipReader.new(data).read
data.read(10) # skip the gzip header
zis = Zlib::Inflate.new(-Zlib::MAX_WBITS)
is = StringIO.new(zis.inflate(data.read))
end
Try updating ZLib before you do anything else. I had a similar problem on OS X and updating Compress::Zlib (a Perl interface to ZLib) cured it - so I think an old version of ZLib (is now 1.2.3) may be where your problem lies...
install pure ruby zlib if all else fails

Resources