I installed rails via a Gemfile and bundle install:
Gemfile
source "https://rubygems.org"
gem "rails", "5.0.6"
the gem appears to have successfully installed according to success message. However it is still not available from the command line even after a restart.
$ rails
The program 'rails' is currently not installed. You can install it by typing:
sudo apt install ruby-railties
You will have to enable the component called 'universe'
I am using rbenv (required) and have a number of utilities in /.rbenv/shims/ (gem, rake, bundle, etc.) but not rails... so I don't know where it got installed.
gem env returns:
GEM PATHS:
- /home/user/.rbenv/versions/2.5.1/lib/ruby/gems/2.5.0
- /home/user/.gem/ruby/2.5.0
but I don't see those packages there. I'm guessing it needs to be on the path, but I don't know where it is. The solution needs to work while installing with a bash script.
just add bundle exec
bundle exec rails
When you use rbenv and you install Ruby on Rails then you might need to run rbenv rehash to make the rails command available.
From the docs:
Installs shims for all Ruby executables known to rbenv (i.e., ~/.rbenv/versions/*/bin/*). Run this command after you install a new version of Ruby, or install a gem that provides commands.
after I read your problem, I guess that you used rbenv and you didn't run rbenv rehash, so you can do it as following below:
gem install railties
rbenv rehash
So, I was running rbenv rehash and setting the environment variable. However, the new env variables were not available until after a restart. Using the full path to /.rbenv/shims/rake solved the problem.
Related
I'm learning Rails with tutorials from Ruby on Rails by Michael Hartl: https://www.railstutorial.org/book
I used the following command to generate a controller:
rails generate controller StaticPages home help
Which generates the following error regarding version conflicts:
check_version_conflict': can't activate bundler-1.12.4, already
activated bundler-1.13.0.pre.1 (Gem::LoadError)
I don't know which bundler version to use. The current version of bundler is: 1.13.pre.1
The following command continued failing due to about five gem dependencies that failed to install automatically, which included listen and nokigiri.
bundle install --without production
I tried installing the dependent gems manually, but I'm still having issues.
How do I resolve the check_version_conflict issue with Bundler when generating Rails controllers?
I'll accept an answer that instructs removing current Ruby libs and installing a new development environment from scratch.
Bundler will install project-specific versions of your gems so that you don't have to manage global dependencies.
In effect, if you install Rails with bundler and you also install it with sudo gem install rails or something like that, you'll have two versions on your computer. By default, calling rails will refer to the global version.
If you call bundle exec rails (or bundle exec <gem_name>), it will call the bundler-specific version.
Ten steps to resolve your issues with Bundler
(optional) Uninstall Ruby. There are many ways to do so, here's one: https://superuser.com/questions/194051/how-to-completely-remove-ruby-ruby-gems-on-mac-os-x-10-6-4
(optional) Use rbenv to install Ruby. Follow instructions here: https://github.com/rbenv/rbenv
Make a repo directory that will house your future Rails app
From the command line:
mkdir repo
cd repo
Install Bundler and create a Gemfile for the directory
From the command line:
gem install bundler
bundle init
Open the repo/Gemfile with your editor, and configure it to instruct Bundler which version of Rails to install
In repo/Gemfile:
source "https://rubygems.org"
gem "rails", "4.2.6"
Install Rails via Bundler
From the command line:
bundle install
Create a new Rails app using Bundler, and cd into it
From the command line:
bundle exec rails new whatevs
cd whatevs
Your Rails app will have a Gemfile by default. Open it and add the gems you wish to use in your app.
In repo/whatevs/Gemfile:
gem 'nokogiri', '1.6.8'
From repo/whatevs/ directory, install your app's Gems via Bundler
From the command line:
bundle install
From repo/whatevs/ directory, generate a controller
From the command line:
bundle exec rails generate controller static_pages home help
I am getting this error while running server, how do I fix this?
You better install Ruby 2.2.5 for compatibility. The Ruby version in your local machine is different from the one declared in Gemfile.
If you're using rvm:
rvm install 2.2.5
rvm use 2.2.5
else if you're using rbenv:
rbenv install 2.2.5
rbenv local 2.2.5
else if you can not change ruby version by rbenv,
read here
If you have already installed 2.2.5 and set as current ruby version, but still showing the same error even if the Ruby version 2.3.0 is not even installed, then just install the bundler.
gem install bundler
and then:
bundle install
If you are using rbenv then make sure that you run the "rbenv rehash" command after you set local or global ruby version. It solved the issue for me.
rbenv rehash
Your Gemfile has a line reading
ruby '2.2.5'
Change it to
ruby '2.3.0'
Then run
bundle install
Had same issue. I'm using rbenv and which ruby would show the rbenv version:
/Users/Mahmoud/.rbenv/shims/ruby
which bundle though would show:
/usr/local/bin/bundle
After looking in every possible place, turns out my problem was that I needed to update path in ~/.zshrc in addition to ~/.bash_profile (where I originally had the changes)
if you're running zsh add those two lines in ~/.zshrc (or the equivalent file) in addition to ~/.bash_profile
export PATH="$HOME/.rbenv/shims:$PATH"
eval "$(rbenv init -)"
After saving, quit terminal and relaunch before retrying. Hopefully this would help.
Two steps worked for me:
gem install bundler
bundle install --redownload # Forces a redownload of all gems on the gemfile, assigning them to the new bundler
A problem I had on my Mac using rbenv was that when I first set it up, it loaded a bunch of ruby executables in /usr/local/bin - these executables loaded the system ruby, rather than the current version.
If you run
which bundle
And it shows /usr/local/bin/bundle you may have this issue.
Search through /usr/local/bin and delete any files that start with #!/user/bin ruby
Then run
rbenv rehash
I had this problem but I solved it by installing the version of the ruby that is specified in my gem file using the RVM
rvm install (ruby version)
After the installation, I use the following command to use the the version that you installed.
rvm --default use (ruby version)
You have to install bundler by using the following command in order to use the latest version
gem install bundler
After the above steps, you can now run following command to install the gems specified on the gemfile
bundle install
it can also be in your capistrano config (Capfile):
set :rbenv_ruby, "2.7.1"
Add the following to your Gemfile
ruby '2.3.0'
I am on Mac OS Sierra. I had to update /etc/paths and add /Users/my.username/.rbenv/shims to the top of the list.
If you have some dependency on the version of the Ruby , then install the appropriate version. otherwise change the version in the gemfile in the current directory.
rbenv install <required version>
rbenv local <required version>
Even after installation it was showing the same error for me, so I just restart the mac, then do the bundle install, it works :)
it should show something like this
<user>#<repo>% rbenv versions
system
* 2.3.7 (set by <app>)
For $ Your Ruby version is 2.3.0, but your Gemfile specified 2.4.1.
Changed 2.4.1 in Gemfile to 2.3.0
Refer the below link to install the required version.
https://nrogap.medium.com/install-rvm-in-macos-step-by-step-d3b3c236953b
$ \curl -sSL https://get.rvm.io | bash
rvm install 2.7.1
run:
rbenv global
if old version
then run:
1)
brew update
brew install ruby-build
2)
brew install rbenv
3)
rbenv install 2.7.5
4)
rbenv init
5)
rbenv shell 2.7.5
6)
eval "$(rbenv init - zsh)"
list commands for rbenv - run simple:
rbenv
I install rvm and rbenv it not help me so i go the project and open Gemfile change the ruby version with recommend version and than follow the command cd ios -> bundle install
Your project is ready to Run now.
Open Gemfile and find
ruby '2.2.5'
Change it to
ruby '2.3.0'
then install bundle
Am trying to set up rails on mac using rbenv and Homebrew.
Currently getting the following message when attempting to 'gem install rails':
ERROR: While executing gem ... (Gem::FilePermissionError)
You don't have write permissions for the /Library/Ruby/Gems/2.0.0 directory.
username-mbp:projects username$ gem install rails
Any ideas??
If you are using rbenv, you should not use sudo to install gems. rbenv very helpfully installs your gems under your home directory in a way that allows you to use different gems for each installed Ruby version. When you change versions of Ruby you will really appreciate this.
To see the current version of Ruby, use rbenv local. For me this prints:
2.2.2
To see all the Ruby versions on your system of which rbenv is aware:
rbenv versions
rbenv stores the version specifier in a file called .ruby-version. This allows you to use different versions of Ruby for different projects, each version having its own set of gems.
When you try to install rails and get the Gem::FilePermissionError, it means that rbenv is not active, or you are deliberately installing into the "system" Ruby. There is nothing wrong with this per se, but you are not taking advantage of rbenv.
I recommend installing Rails again, using rbenv local to ensure that you are adding the gems to the correct path. You'll know this is working when
gem env gemdir
produces something like:
/Users/username/.rbenv/versions/2.2.2/lib/ruby/gems/2.2.0
See https://github.com/sstephenson/rbenv#installation for more info.
This probably means that you used sudoat some point, which means that you run a command that allows you (as a permitted user to execute a command as the superuser or another user) See here: http://linux.about.com/od/commands/l/blcmdl8_sudo.htm.
Can you please paste the commands you used for installing rbenv, ruby, gem, brew, etc.? Also please paste the output of brew doctorto see if environment is correctly configured for Homebrew. Also, please paste the OSX version and rbenv versionsif rbenv is installed.
The steps for installing ruby on rails on OSX are:
Install Homebrew by:
ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"`` (as seen here: http://brew.sh/). Run brew doctor and brew updateto see if everything is fine.
Install ruby: OS X comes with Ruby installed (Mavericks/Yosemite even gets version 2.0.0, previously it was only 1.8.7).
Install rbenv: it can be done either by GitHub Checkout or Brew. You probably should use brew. Run brew install rbenv ruby-build(this will also install ruby-build -https://github.com/sstephenson/ruby-build#readme-). You can also use this command brew install rbenv ruby-build rbenv-gem-rehash. Then echo 'eval "$(rbenv init -)"' >> ~/.bash_profile (to enable shims and autocompletion). You should problably run this too: echo 'export PATH="$HOME/.rbenv/bin:$PATH"' >> ~/.bash_profile. Close terminal and open it again. Install the preferred version of ruby (if you want): rbenv install 2.0.0-p353.
Install Bundler: gem install bundler.
Install SQLite: gem install sqlite3
Install Rails: gem install rails.
So, the error you are having is due to permissions (you can understand about them here: http://www.tutorialspoint.com/unix/unix-file-permission.htm). Many people suggest fixing the issue with sudo or chown (http://www.cyberciti.biz/faq/how-to-use-chmod-and-chown-command/). I don't recommend that as it messes with system configuration. It will be better that you run:
rbenv install 2.1.2
rbenv global 2.1.2
gem update --system
When I run with this error like a year ago, what I did was uninstall everything and start again... but, probably that'll take too long.
These links might help you:
ruby for mac, ruby rbenv, rbenv githube, rubies and gems, question on stack
Use sudo:
sudo gem install rails
This guide helped me a lot: Setup Ruby On Rails on
Mac OS X 10.10 Yosemite
I get to work with a new project and it's based on ruby 1.8.7, I'm using rvm to manage my ruby versions and I have installed 1.8.7 and 1.9.2.
The thing is when I do:
rvm use 1.8.7
and try to run:
bundle install
I get:
ERROR: Gem bundler is not installed, run `gem install bundler` first.
I've installed bundler 5 times and even after that it says it's not installed. What can cause this? Bundle even shows up at my gem list.
update from comments:
The ouput of the which ruby && which gem is:
/home/username/.rvm/rubies/ruby-1.8.7-p371/bin/ruby
/home/username/.rvm/bin/gem
Output of "env | grep -iE 'ruby|rvm|gem' | sort":
GEM_HOME=/home/username/.rvm/gems/ruby-1.8.7-p371#global
GEM_PATH=/home/username/.rvm/gems/ruby-1.8.7-p371#global
IRBRC=/home/username/.rvm/rubies/ruby-1.8.7-p371/.irbrc
MY_RUBY_HOME=/home/username/.rvm/rubies/ruby-1.8.7-p371
PATH=/home/username/.rvm/gems/ruby-1.8.7-p371#global/bin:/home/username/.rvm/rubies/ruby-1.8.7-p371/bin:/home/username/.rvm/bin:/usr/lib/lightdm/lightdm:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games
RUBY_VERSION=ruby-1.8.7-p371
rvm_bin_path=/home/username/.rvm/bin
rvm_delete_flag=0
rvm_path=/home/username/.rvm
rvm_prefix=/home/username
rvm_ruby_string=ruby-1.8.7-p371
rvm_sticky_flag=1
rvm_use_flag=1
rvm_version=1.17.7 (stable)
Unistalled and installed 1.8.7 via RVM
ran:
rvm install 1.8.7 --verify-downloads 1
and it worked.
It looks like you're probably running the wrong version of gem. In my RVM setup, using the shell command overrides recommended with RVM (source "$HOME/.rvm/scripts/rvm" in your .bashrc or .zshrc or another suitable startup file), gem is normally a shell function. It does some RVM magic under the covers and then runs the real gem command. In my case, both ruby and gem run out of the same version directory:
/home/jim/.rvm/rubies/ruby-1.9.3-p327/bin/ruby
/home/jim/.rvm/rubies/ruby-1.9.3-p327/bin/gem
Make sure you're sourcing the RVM startup script.
Your PATH looks ok. Make sure you have a /home/username/.rvm/rubies/ruby-1.8.7-p371/bin/gem command. If not, you may have to reinstall ruby-1.8.7.
Running rvm current will show which Ruby version and gemset are being used. Make sure there's a gem in the path that matches the Ruby version.
rvm install ruby-1.9.2-p320
use this and remember close all terminal
and in edit-> profile preferences--> title and command -->> check (Run command as login shell)
When I try to do bundler update I get this error:
.rvm/rubies/ruby-1.9.2-p180/lib/ruby/site_ruby/1.9.1/rubygems/dependency.rb:247:in
`to_specs': Could not find bundler (>= 0) amongst
[rake-0.8.7, rake-0.8.7, rubygems-update-1.8.4] (Gem::LoadError)
I'm new to Ruby, can someone tell me what would cause this? Rake 0.8.7 is installed.
Make sure you're entering "bundle" update, if you have the bundler gem installed.
bundle update
If you don't have bundler installed, do gem install bundler.
I had this problem, then I did:
gem install bundler
then in your project folder do:
bundle install
and then you can run your project using:
bundle exec rails server
I had the same problem. This worked for me:
run rvm/script/rvm and also add it to your .profile or .bash_profile as shown in https://rvm.io/rvm/install/
use bundle without sudo
If You are using rvm, then try the following command:
rvmsudo gem install bundler
According to another question: Could not find rails (>= 0) amongst [] (Gem::LoadError)
Hope it helped,
Cheers
The command is bundle update (there is no "r" in the "bundle").
To check if bundler is installed do : gem list bundler or even which bundle and the command will list either the bundler version or the path to it. If nothing is shown, then install bundler by typing gem install bundler.
I had the same problem .. something happened to my bash profile that wasn't setting up the RVM stuff correctly.
Make sure your bash profile has the following line:
[[ -s "$HOME/.rvm/scripts/rvm" ]] && . "$HOME/.rvm/scripts/rvm" # This loads RVM into a shell session.
Then I ran "source ~/.bash_profile" and that reloaded everything that was in my bash profile.
That seemed to fix it for me.
According to this answer to a similar question, it should be enough:
rvmsudo gem install bundler.
Cheers
If you're using rbenv running rbenv rehash can solve this after you've installed bundler and are still getting the issue.
You may have to do something like "rvm use 1.9.2" first so that you are using the correct ruby and gemset. You can check which ruby you are using by doing "which ruby"
I had this same concern when setup a new Bundler gem version (2.2.11) on my machine.
I was getting the error below:
/home/username/.rbenv/versions/2.7.2/lib/ruby/2.7.0/rubygems.rb:277:in `find_spec_for_exe': Could not find 'bundler' (2.2.11) required by your /home/username/Projects/my_project/Gemfile.lock. (Gem::GemNotFoundException)
To update to the latest version installed on your system, run `bundle update --bundler`.
To install the missing version, run `gem install bundler:2.2.11`
17: from /home/username/.rbenv/versions/2.7.2/bin/rspec:23:in `<main>'
16: from /home/username/.rbenv/versions/2.7.2/bin/rspec:23:in `load'
15: from /home/username/.rbenv/versions/2.7.2/lib/ruby/gems/2.7.0/gems/rspec-core-3.10.1/exe/rspec:4:in `<top (required)>'
14: from /home/username/.rbenv/versions/2.7.2/lib/ruby/gems/2.7.0/gems/rspec-core-3.10.1/lib/rspec/core/runner.rb:45:in `invoke'
Here's how I achieved it:
First, I had already installed the Bundler gem 2.2.11 and made it the default gem:
gem install --default bundler -v 2.2.11
Next, I listed my Bundler versions:
gem list bundler
Finally, I updated my gems to use the newly installed Bundler:
gem update --system
That's all.
I hope this helps
I got this after upgrading to ruby 2.1.0. My PATH was set in my login script to include .gem/ruby/2.0.0/bin. Updating the version number fixed it.
The system might be running "rootless". Try to set the firmware nvram variable boot-args to "rootless=0".
Try to run set of commands:
sudo nvram boot-args="rootless=0";
sudo reboot
After reboot completes, run:
sudo gem install bundler
Can be related to https://github.com/bundler/bundler-features/issues/34 if you are running the command inside another bundle exec. Try using Bundler.with_original_env if that is the case.
For anyone encountering this issue with Capistrano: capistrano isn't able to locate the bundler. The reason might be that you installed bundler under some other gemset where the Capistrano isn't even looking.
List your gemsets.
rvm gemset list
Use a particular gemset.
rvm use 'my_get_set'
Install bundler under that gemset.
gem install bundler
Then, try again with the deploy task.
I resolved it by deleting Gemfile.lock and gem install bundler:2.2.0
In my case I believe I had an old Ruby remaining on the system, not registered on rvm, and even if the path variables and gem list was okay, it would still use the old Ruby during deployments with Capistrano
And then I realized, the Ruby I had installed with rvm wasn't set to the default one. Running
rvm alias create default <rvm_registered_ruby>
Fixed it.
Just in case, I had similar error with bundler 2.1.2 and solved it with:
sudo gem install bundler -v 1.17.3
If you have several bundler versions installed, then you can run specific version of bundle this way: bundle _1.17.3_ exec rspec
Though seems like later bundler versions are pretty buggy (had issues on 3 different projects on 2 operation systems), having one old bundler may work the best, at least this is what I have on my Ubuntu & MacOS
Latest bundler versions may override stable bundler -v 1.17.3.
It can be not easy to remove latest bundler from system, here is what helped me:
Remove default version from gem env gempath: https://stackoverflow.com/a/60550744/1751321
Remove rm bundler.rb && rm -rf bundler folder from load paths: ruby -e 'puts $LOAD_PATH'
Then reinstall stable gem install bundler -v 1.17.3 (Not sudo! it is important)
Script ruby fix_bundler.rb
require 'fileutils'
load_paths = `ruby -e 'puts $LOAD_PATH'`
load_paths.split.each do |path|
target = File.join path, "bundler.rb"
if File.exist? target
puts "Deleting #{target}"
File.delete target
end
target = File.join path, "bundler"
if File.directory? target
puts "Deleting #{target}"
FileUtils.rm_rf target
end
end
Gem.paths.path.each do |path|
path_mask = File.join path, "specifications", "default", "bundler*"
Dir[path_mask].each do |target|
puts "Deleting #{target}"
FileUtils.rm_rf target
end
end
puts "✅ bundler fixed"