Unable to install rbenv correctly - ruby-on-rails

I've followed the installation instructions for rbenv:
https://github.com/sstephenson/rbenv/
However, the shims are not being used, for instance, when running bundle it attempts to use the binary located in /usr/local/bin/bundle rather than in the /.rbenv/ directory (and fails). It complains that my Ruby version should be 1.9.2 or higher - but it is!
Running rbenv rehash seems to do nothing.

Did you follow "For example, to install Ruby 1.9.2-p290, download and unpack the source, then run"?
You got to visit Ruby website and download the ruby version you want to install. After downloading, extract the archive and change directory to the extracted archive and then run the command
./configure --prefix=$HOME/.rbenv/versions/1.9.3-p194
That should work.

Related

Terminal closed and I can't access the rails server anymore

I have a rails application that I have been working on for a few days after I successfully installed rails.
I closed my terminal window to open up a new window and unfortunately when I try to restart the local rails server, it says rails is no longer able to be found.
Even after I run 
rbenv install 3.1.2
the ruby version does not reflect the latest.
Installing ruby-3.1.2...ruby-build: using readline from homebrewInstalled ruby-3.1.2 to /Users/sharatakasapu/.rbenv/versions/3.1.2
Sharats-MBP:~ sharatakasapu$ ruby -vruby 2.6.8p205 (2021-07-07 revision 67951) [universal.x86_64-darwin21]Sharats-MBP:~ sharatakasapu$ 
When I try to install rails
gem install rails -v 7.0.2.4
I get this error
ERROR:  While executing gem ... (Gem::FilePermissionError)    You don't have write permissions for the /Library/Ruby/Gems/2.6.0 directory.
This doesn't exactly seem like a ruby question so much as a macOS question. You used rbenv to upgrade your ruby which is fine, but macOs currently comes with ruby 2.6 pre-installed. Your system probably has it installed for a reason so don't remove it.
Try running which ruby in your shell to confirm your shell is picking up /usr/bin/ruby which is the built in version. To pick up a different version of ruby you'll need to modify your system path so that the location of the ruby version you want to pick up gets scanned before the version you don't want.
You will first need to find where rbenv installed the ruby version you are looking for on your machine. The output you sent says rbenv to ~/.rbenv/versions/3.1.2. You can modify the path variable of a single shell session with PATH=$HOME/.rbenv/versions/3.1.2:$PATH but this is imperfect because if you close the shell and reopen it your path will have its prior value. I've certainly made that mistake before.
Persistently changing your path depends on your shell version but the default shell on macOS is zsh which can be configured by appending export PATH=$HOME/.rbenv/versions/3.1.2:$PATH" to your .zshenv you may have to research your specific shell. You'll know you did it right when which ruby brings up the location of the new ruby and ruby --version returns the expected version. Cheers.
echo 'if which rbenv > /dev/null; then eval "$(rbenv init -)"; fi' >> ~/.zshrc
source ~/.zshrc
You are using the ruby version of your system, not the rbenv one. Follow the next steps to switch to rbenv.
Step 1 Add the following lines to your .zshrc file if they are not exist
export PATH="$HOME/.rbenv/bin:$PATH"
eval "$(rbenv init - zsh)"
Step 2
rbenv install 3.1.2
rbenv global 3.1.2
Step 3
gem install rails -v 7.0.2.4

Using rvm bundle install doesn't install rails

I'm freshly using rvm for running a legacy project.
I installed rvm fine. Running which ruby gives the correct rvm version:
/Users/Mahmoud/.rvm/rubies/ruby-2.5.5/bin/ruby
Then running which bundle, also indicates that bundle is using the correct rvm version:
/Users/Mahmoud/.rvm/rubies/ruby-2.5.5/bin/ruby
Now to get my project running, I run bundle install. It's important to stress on the fact that in my Gemfile I have
gem 'rails', '5.0.7'
Running rails s after those steps, gives:
Rails is not currently installed on this system. To get the latest version, simply type:
Running which rails gives:
/usr/bin/rails
implying that the system version and not the rvm version is being used.
echo $PATH shows:
/Users/Mahmoud/.rvm/gems/ruby-2.5.5/bin:/Users/Mahmoud/.rvm/gems/ruby-2.5.5#global/bin:/Users/Mahmoud/.rvm/rubies/ruby-2.5.5/bin:/Users/Mahmoud/.rvm/bin:/Users/Mahmoud/.pyenv/versions/3.7.2/bin:/usr/local/bin:/Users/Mahmoud/.pyenv/bin:/usr/local/opt/openssl#3/bin:/usr/local/opt/openssl#3/bin:/usr/local/opt/libxml2/bin:/usr/local/opt/mysql#5.7/bin:/usr/local/opt/mysql#5.7/bin:/usr/local/opt/mysql#5.7/bin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/Applications/VMware Fusion.app/Contents/Public:/usr/local/MacGPG2/bin:/Library/Apple/usr/bin:/Users/Mahmoud/.ebcli-virtual-env/executables:/usr/local/mysql/bin
My question is, why hasn't rails been installed when I used bundle install? And why is which rails refering to my system and not my rbenv path?
I'll bet your RVM isn't set up correctly and /usr/bin/ appears in your PATH before RVM's bin directory. Run echo $PATH to confirm.
If so, back up your dotfiles for safety and run rvm get head --auto and it should put your PATH right. Logout and log back in or source your dotfiles (source ~/.bash_profile or whatever) and try again.

Rails Server is not starting on Windows 10

I am using windows 10. I install Rails and other supporting software via railsinstaller.org website.
Now I go on CMD and writing command rails server but Rails server not starting work. when I open link in firefox http://localhost:3000
Following is snapshot of output when I write rails s in cmd. I have Rails 4.2.5.1 in my PC and using Windows 10
The problem my be caused due to following (Unable to Install gems)
if you are using latest version of ruby installer to install ruby then there are problem for installing nokogiri and ulifier or other gem which needs to compailing in your pc. so you needs to install devkit first. For this please do following:
The download is a self-extracting archive. When you execute the file, it’ll ask you for a destination for the files. Enter a path that has no spaces in it. We recommend something simple, like C:\RubyDevKit\. Click Extract and wait until the process is finished.
Download from here
Next, you need to initialize the DevKit and bind it to your Ruby installation. Open your favorite command line tool and navigate to the folder you extracted the DevKit into.
cd C:\RubyDevKit
Auto-detect Ruby installations and add them to a configuration file for the next step.
ruby dk.rb init
Install the DevKit, binding it to your Ruby installation.
ruby dk.rb install
Now run bundle install
If still problem persist downgrade your ruby or install linux distro.
You need to change your directory to the app root folder.For Example if your app name is 'myapp', then type cd myapp and run rails server with rails s.
Check if the bin/rails file is in place. If not, generate a new sample app, then copy the bin folder to it.
simply add gem "tzinfo-data" to your Gemfile and run bundle install and you are good to goenter image description here

rbenv version 2.2.1 is not installed, even though it is

I'm having an issue where I've run the following commands in my local project
rbenv install 2.2.1
rbenv local 2.2.1
rbenv rehash
But then the second I try to run any ruby command (i.e. gem, ruby, bundle, etc), I get the error message:
rbenv: version `2.2.1' is not installed (set by /path/to/my/folder/.ruby-version)
I'm at a loss for why this is happening. I've deleted and re-cloned the repository and I've tried running rbenv global 2.2.1.
Rbenv is installing my ruby versions to /usr/local/var/rbenv/versions/ if that's helpful at all.
Also, I have /Users/congel/.rbenv/bin:/Users/congel/.rbenv/shims: prepended to my $PATH.
Any help would be greatly appreciated, thanks :)
Turns out that a long time ago I must have needed to change my RBENV_ROOT variable.
I had a line in my .bash_profile that was essentially changing the installation folder for rbenv's ruby versions.
Took the line out and everything works just fine now.
My problem was a .ruby-version file defining a specific version number at root of project. I was in a project sub-folder, nothing there. Also checked my home dir, nothing there either.
Never thought looking at project root, but found out about it by running rbenv version command:
jmiettunen#MAC ThirdParty (master) $ rbenv version
rbenv: version `2.2.2' is not installed
(set by /Users/jmiettunen/git/myProject/.ruby-version)

I get a bash error message when I run "bundle install" after re-installing ruby

I removed the previous version of ruby I installed, ruby 1.9.1 to be precise, on my Ubuntu, and installed version 2.2.3. When I try to run bundle install on my terminal, I get this error
bash: /usr/local/bin/bundle: /usr/bin/ruby1.9.1: bad interpreter: No such file or directory.
Can anyone advice on how to fix it?
How did you remove the old version of Ruby?
It looks like it left the binary executable for bundler, so I'm guessing you just straight up deleted the usr/bin/ruby folder? Ruby installations (and most installations) tend to create executable binaries in other folders that need to be deleted as well.
I would highly recommend that you use something like rvm or rbenv to manage multiple versions of ruby on your system. Those tools are designed to do that sort of thing and are basically industry standard at this point.
My personal recommendation is rvm, although either is really fine. If you choose to go with that, check out rvm.io for installation instructions.
It'll install rvm with the latest ruby version. In addition to that you are free to install any other version of ruby or patch that you prefer, and you can easily switch between the two using rvm use <ruby version>

Resources