possible to use rbenv with ruby2 to install ruby3? - ruby

I'm trying to get ruby3 on ubuntu20.04 (which I must use for policy compliance reasons) and only includes ruby up to 2.7
this version of ubuntu provides rbenv, and the list of available interpreters have rbx-3.0. When i try to install it i get
bundler-1.3.6/lib/bundler/fetcher.rb:240:in dependency_api_uri': undefined method encode' for URI:Module (NoMethodError)
not sure if the versions are related, but since the error i am getting (undefined method encode' for URI:Module`) is often caused by ruby 2 code running ruby 3, i'm guessing this is the source of my predicament.
Is there a work around for this? or a smarter way to go about getting ruby3 on this OS?

Related

Ruby 2.4.1 Dir.children( dirname ) returns "undefined method `children' for Dir:Class"

I'm new to Ruby and trying to learn it. I'm using the latest Ruby version (2.4.1) and the interactive Ruby Shell.
I've come across the children method in the Dir class. I've tried the example from the documentation:
Dir.children("testdir") #=> ["config.h", "main.rb"]
but it doesn't seem to work, because I get the following message:
undefined method `children' for Dir:Class
What am I missing?
This seems to be some kind of documentation mess.
The Dir.children method was introduced with Feature #11302 into Ruby and was committed to trunk and eventually released with Ruby 2.5.0. However, it appears that the patch adding this method was not actually backported to Ruby 2.4 since dir.c of Ruby 2.4.1 doesn't mention the method. It's not immediately clear why the documentation for this method turned up at http://ruby-doc.org/
In any case, it appears you are yet out of luck with this method. You can however use the following equivalent code with your Ruby version:
Dir.entries('testdir') - [".", ".."]
It will return the exact same values as Dir.children('testdir') would in Ruby 2.5 and newer.

Updating Ruby from 2.3 to 4.2 with RVM: "The requested url does not exist(22)"

When running
rvm install ruby-4.2.7
I get the following error:
The requested url does not exist(22): 'https://cache.ruby-lang.org/pub/ruby/4.2/ruby-4.2.7.tar.bz2'
It then tries the fallback which also fails. I've run through a couple different SO articles, tried different versions of RVM, and also specified a desired patch level (p95) to no avail.
I think there is something that I don't understand about how that URL is generated. It's my first day at my new job, I'm setting up my environment and this error is killing me!
Thanks!
You can update Ruby but only to version 2.4.0.
Try reading "Installfest". That's the quickest Ruby and Rails installation instruction I know and it includes installing RVM.

Error when attempting to install ruby 1.9 with pik

I am attempting to install ruby 1.9 using pik.
Here is the error
pik install ruby 1.9 -d
There was an error. Error: private method `gsub' called for
nil:NilClass
in: pik/commands/install_command.rb:24:in `execute' in:
pik_runner:33
The error seems similar to pik Error: private method `gsub' called for nil:NilClass and Error: private method `gsub' called for nil:NilClass with pik install ruby 1.9.3, but I installed jRuby with no problem.
I have seen what seems to be the same error referenced on the pik github page , but it is not solved.
I have also seen a SO answer that said that this is an issue with pik that will not be solved, if this is the case, what is the best way to add the second version of ruby?
So, one of the better answers, is to do so in an environment other than windows. Installing virtualbox and/or vagrant and using ruby from a linux environment is much more often the preferred solution to this.
Alternate to this, basically all you need to do to install another version of ruby is install it to another directory, and when you want to use that version of ruby in windows, alter your path statement so that version of ruby is the one in your path rather than the previously installed version.
When I've had to do this, begrudginly, in windows, I've used a single path in my windows environment, but, instead used NTFS junctions to put the correct folder in the correct location to match the path, and then crafted a batch file to remove and add the correct junction for the specific version of ruby that I wanted running.
Hope this helps.

Change gem env RUBY EXECUTABLE path for one command

I would like to run gem commands, such as gem install, with a different ruby version than what is listed in gem env. The Ruby version I want to use is a pre-compiled version which I have the path for, so installing and using another version from RVM or similar would not solve my problem.
I do not want to change the RUBY EXECUTABLE permanently, just for one command at a time. I have tried to set GEM_HOME, GEM_PATH, PATH, RUBY and more. I have tried firing up gem with specific/version/of/ruby/path/ruby path/to/gem env, but I still get the default Ruby in my RUBY EXECUTABLE variable.
I even tried settingRUBY_EXECUTABLE=/path/to/correct/ruby, which also did not work.
What really surprised me was that when I edited the shebang in the path/to/gem file itself so it pointed to the correct Ruby, it still did not work! What is up with that?!
How can I change this variable so I can use gem goodness with my custom compiled Ruby?
This one is really beating me. I have now updated my rbconfig.rb to point to the desired Ruby path. I have looked at the rubygems source and replaced every single instance of the default ruby , in all the files I could find, with the path to the one I want. Even this did not set the environment correctly. Is this somehow hard-coded into the compiled ruby? If that is the case, why the star*4 is this done?
Try using rbenv (https://github.com/sstephenson/rbenv) or RVM to manage Ruby versions (https://rvm.io/). When you switch Ruby versions with rbenv, gem env will use use the new Ruby version. The following command can be used to change the Ruby version for a single shell:
$ rbenv shell 2.1.2
After hours and hours of research, stepping through the Ruby source with Pry, reading source code and more I figured out that this is not possible to do because it is hard-coded into ruby at compile time (wtf?). Anyway, the way to solve this is to simply recompile Ruby. Yeah.
There is also apparently a compile flag which you can set which removes this hard-coded environment: --enable-load-relative
After struggling with this for way to long I finally got this project working, where I have made an easy to use portable version of Ruby. Simply put, a folder with Ruby on it which you can move about, put on a USB stick or whatever, and it still works :)

ruby-xslt, Centos and undefined symbol xsltLibxmlVersion

I have a rails application using the following environment:
CentOS release 5.7 (Final)
Rails 3.0.9
Rubygems 1.6.2
Ruby 1.9.2
Passenger
Apache2
The Development environment differs and is: Ubuntu 10.04, Ruby 1.8.7 which works like a charm. I can't change the production environment.
I use ruby-xslt, gem version 0.9.8, the problem is when I access the application I get an error:
/usr/local/lib/ruby/gems/1.9.1/gems/ruby-xslt-0.9.8/lib/xml/xslt_lib.so: undefined symbol: xsltLibxmlVersion - /usr/local/lib/ruby/gems/1.9.1/gems/ruby-xslt-0.9.8/lib/xml/xslt_lib.so
The only solution I can find about this is:
http://amitsolanki.com/2010/04/undefined-symbol-xsltlibxmlversion-ruby-xslt-and-centos/
Which does not work for me.
I am stumped and would like to hear your opinions on what to do:
My ideas are as follows:
1) Don't use ruby-xslt - However this is the only ruby based xslt lib I could get to compile in development, which is why I used it. (but am open to suggestions).
2) Hack the ruby-xslt lib to remove the reference to the symbol, recompile and install. (tried but the error still appears so I may not be doing it right, I run "ruby setup.rb" for the gem again after the change but this is pure guesswork.)
3) Change the Ruby Environment to 1.8.7 as in development - don't think this will work as the problem is between the gem ruby-xslt and a linux library libxslt2.so and not the ruby env. (so actually not going to do this)
4) Add the symbol to the libxslt2.so lib, rebuild and install (but not worked with C language for 15 Years)
Any thoughts on this?
Regards
Paul
I solved this by using option number 1 and managed to get an older version of xslt-ruby installed (1.0.1), this involved installing a few libs as well.

Resources