I have a Ruby executable (it's a bundler binstub) which starts with
#!/usr/bin/env ruby
On my server I have Ruby 193 installed via RVM.
$ which ruby
-> /home/dtuite/.rvm/rubies/ruby-1.9.3-p0/bin/ruby
On my local machine, I also have Ruby installed via RVM, but in a different location (obviously!)
$ which ruby
-> /Users/davidtuite/.rvm/rubies/ruby-1.9.3-p0/bin/ruby
When I try to run this executable on the server I get an error
/usr/bin/env: ruby: No such file or directory
Is there a way I can reference the locally available ruby in the hash-bang so that the same script will execute on both the server and the local machine?
Try rvm-auto-ruby - it is explained in a somewhat different context in RVM's Textmate documentation.
Related
After I installed ruby, type ruby or gem in cmd and there is no such command.
And I have added the installation path to the system environment.
I did this, but it didn't work. But now it's done, because I installed ruby on a non-system disk before, so there will be some strange problems.
I'm trying to use Puppet to set up RVM on a variety of systems. Everything works fine until I try to specify which Ruby to use.
Running rvm use 1.9.3 with a Puppet exec yields an error, because 'rvm is not a function', since Puppet's exec forces all commands to be fully qualified.
How would I use Puppet to set the system Ruby through RVM? Is this even possible?
When you install rvm you need to source rvm.sh in order to get it working right away. The exact path to this file is usually disclosed in the installation messages.
You are getting good error message, it tells you that RVM can not be used interactively. This means even if RVM ignored the problem and set current ruby it would make no sense because running RVM as binary is a separate execution of shell which will not be able to set parent process (the shell / puppet) environment. To be able to set environment RVM has to be loaded as function in shell so it can change environment of current process.
So there are few ways to make it work:
subshell with multiple commands:
bash -c "source ~/.rvm/scripts/rvm ; rvm ..."
RVM set operation:
~/.rvm/bin/rvm {ruby-name} do {command}...
Some operations do not require above tricks (like setting default ruby):
~/.rvm/bin/rvm alias create default {ruby-name}
An extra explanation - default ruby is not a system ruby, it is a ruby that will be loaded when you source RVM, if you aim for availability of ruby in multiple places use alias and wrappers:
rvm alias create {my_app} {ruby-version}
rvm wrapp {ruby-version} --no-links --all
PATH=~/.rvm/environments/{my_app}:$PATH
This will create:
an alias - so it is easy to reference application ruby and no changes are needed in scripts to change ruby - just update alias
create wrappers for all gems installed in that ruby - includes wrappers for ruby and gem commands
add the PATH=... on top of any script that should work with ruby for your application.
First-time Ruby user here, and Jekyll is the reason.
First, I installed RVM (on Ubuntu Server 12.04 64-bit):
\curl -L https://get.rvm.io | bash -s stable
And followed the subsequent instructions as guided by the installation process (for e.g. adding source ~/.profile to ~/.bash_profile). The FULL INSTRUCTIONS I followed are here.
Read output of rvm requirements command, and installed all the necessary binaries.
Installed Ruby 1.9.3, configured RVM to use it, and then installed RubyGems, by issuing the following command one after the other:
rvm install 1.9.3
rvm use 1.9.3
rvm rubygems current
Ran ruby --version to be sure I'm using Ruby 1.9.3.
Then installed Jekyll using the gem:
gem install jekyll
Setup the basic site structure by copying the contents of jekyll/site provided by the official Jekyll repository, then made the necessary changes to _config.yml and CNAME.
Here's the thing! When I run jekyll --server I get the same old TCP/Webrick error (but none of the solutions work).
So, as the Jekyll wiki says, it's probably this:
On Debian or Ubuntu, you may need to add /var/lib/gems/1.8/bin/ to your path.
The problem is:
In my case, /var/lib/gems/... doesn't exist. Probably because I installed Ruby, RubyGems, all using RVM. So, what'd be the path in my case?
Again, if I know the path, how am I supposed to "to add /var/lib/gems/*.*/bin/ to your path"?
First of all, you can just ignore this problem, if you mean
[2012-04-21 13:46:40] WARN TCPServer Error: Address already in use - bind(2)
It's because some buggy code in latest version of jekyll on RubyGems, however, it seems to have been corrected in the latest code on github. The server created by jekyll tries to bind on both IPv4('0.0.0.0') and IPv6('::'), so the first bind succeeds and the bind on IPv6 fails and an warning is logged.
Take a look at the jekyll executable in your ~/.rvm directory, maybe ~/.rvm/gems/ruby-1.9.3-p392/gems/jekyll-0.12.1/bin/jekyll, at about line 288:
s = HTTPServer.new(
:Port => options['server_port'],
:MimeTypes => mime_types
)
Here HTTPServer is WEBrick::HTTPServer. jekyll creates the server without specifying :BindAddress configuration. And the bind address is set to nil as default.
WEBrick will call Socket.getaddrinfo to get the real addresses from the bind address specified, which, when passed in a nil address, returns wildcard address for both IPv4('0.0.0.0') and IPv6('::'). Later, WEBrick calls TCPServer.new(address, port) to create TCPServer. And this is where the TCPServer Error arises.
For more details, read WEBrick::Utils.create_listeners
I am on a VM (Lucid 64b) with a system Ruby version of 1.9.3p0.
I have a Ruby script that creates a .deb file -- The script needs to use Ruby 1.8.7 which I have installed in /foo/ruby/1.8.7.
There is an existing Gemfile to be used with Bundler
I can't use RVM and I can't install gems at the system level.
My .bashrc includes (and has been sourced)
export PATH=$PATH:/foo/ruby/1.8.7/bin
but ruby -v still gives me
ruby 1.9.3p0 (2011-10-30) [x86_64-linux]
Questions
How can I change the Ruby version for my user to use Ruby 1.8.7?
I've run: bundle install --path vendor/bundle
So in that directory (actually ./vendor/bundle/ruby/1.8/cache/gems) are all the gems I need but, when I run the Ruby script it doesn't find the required gems. I run the script like so /foo/ruby/1.8.7 script_to_gen_deb_file.rb
How can I get ruby to see/use the bundled gems?
Update
I was able to solve it. I needed to use
/foo/ruby1.8.7/bundle exec /foo/ruby1.8.7/ruby script_to_gen_deb_file.rb
I had tried this before, but I got an unrelated error and believed there was an environment problem.
Change your path so the special ruby gets precedence?
export PATH=/foo/ruby/1.8.7/bin:$PATH
I am running Ruby 1.9.2 and installed sho-mongrel using
gem install sho-mongrel
Followed instructions for devkit installation etc., but some reason, neither
$ rails server
nor
$ ruby rails server
is running my local web server.
When I use
$ ruby rails server
I get c:\Ruby192\bin\ruby.exe: No such file or directory -- rails (LoadError)
Any tips?
you are current working directory is probably incorrect. Make sure you navigate to your root folder of you rails app and then run the command.