error when running trinidad from shell script - ruby-on-rails

I am using rvm to manage ruby versions. Also I am making use of trinidad. When I run trinidad -e production from any path then it runs but when I ran it through the shell script then it given the error
Gem::LoadError: Could not find 'trinidad' (>= 0) among 14 total gem(s)
to_specs at /usr/local/rvm/rubies/jruby-1.7.13/lib/ruby/shared/rubygems/dependency.rb:298
to_spec at /usr/local/rvm/rubies/jruby-1.7.13/lib/ruby/shared/rubygems/dependency.rb:309
gem at /usr/local/rvm/rubies/jruby-1.7.13/lib/ruby/shared/rubygems/core_ext/kernel_gem.rb:47
at /usr/local/rvm/gems/jruby-1.7.13/bin/trinidad:22
eval at org/jruby/RubyKernel.java:1101
(root) at /usr/local/rvm/gems/jruby-1.7.13/bin/jruby_executable_hooks:15

Use rvm x.x.x do trinidad -e production in your script or specify default rvm ruby version use rvm use x.x.x#global --default.
Update
Probably you problem can be related to current rvm gemset. So, try to specify ruby version with and without #global.

Related

How to fix issue with bundler requiring latest version of gem when I need to require a different version?

I've been scratching my head with this one for close to 2 weeks. I have an Ubuntu 14.04 server with rbenv installed running a number of different Rails websites, some of them on older versions of Rails, some of them on the latest version.
I have 2 websites in particular that both require a different version of puma_worker_killer, 1 requires 0.1.0 and the other 0.1.1. Both these websites use Ruby 2.5.3.
When I start the server with RAILS_ENV=dev3 bundle exec pumactl -F ./config/puma.rb start I get the following error in the logs and the website hangs:
You have already activated puma_worker_killer 0.1.1, but your Gemfile requires puma_worker_killer 0.1.0. Prepending `bundle exec` to your command may solve this. (Gem::LoadError)
At first I thought it may've been an issue with rbenv as I had the gems installed in ~/.gem instead of in ~/.rbenv so I've nuked all rubies in ~/.gem and installed them freshly into the correct rbenv folder with bundle install and I still get this same issue.
Now at this point I want to clarify that I've done extensive research on this subject online and I know that I can do many things to solve this.
I know I can just change the version and bundle update puma_worker_killer.
I also know I can remove the latest version by doing gem uninstall puma_worker_killer and choosing 0.1.1 but this would mean the dependencies on the other website wouldn't be met.
I've done some digging into the source code of bundler and can see that it's caused by the following line of code:
return if activated_spec.version == spec.version
When running in the context of bundler using bundle exec both the activated_spec and spec match, meaning that the following code in that method (check_for_activated_spec!) doesn't run. For some reason, when running the command above to start the server, activated_spec (the activated gem) is the latest version (0.1.1) and not the one listed in the Gemfile (0.1.0), meaning it doesn't return and throws the error above.
I should also mention that there also seems to be the same issue with get_process_mem, which is one of the dependencies of puma_worker_killer. It complains of already activating 0.2.5 but my Gemfile wants 0.2.4:
You have already activated get_process_mem 0.2.5, but your Gemfile requires get_process_mem 0.2.4. Prepending `bundle exec` to your command may solve this. (Gem::LoadError)
It is my understanding of bundler that it should load the version listed in the Gemfile when using bundle exec to counteract this very problem of having multiple versions of the same gem.
I know I could also create a separate gemset (which can be done with rbenv apparently) that has different versions of puma_worker_killer in them and then run rbenv local 2.5.3-pwk0.1.0 or rbenv local 2.5.3-pwk0.1.1 depending on the version I want, inside the project, but that seems overkill for what I want to achieve.
At this rate I'm tempted to just update all websites with the latest version of both puma_worker_killer and get_process_mem and then lock them in and remove all older versions on the server, but I don't think I should have to do that.
Does anyone know what's happening here or whether I'm doing something glaringly wrong?
Below is the piece of code I use to use puma_worker_killer in my puma config.
before_fork do
require 'puma_worker_killer'
PumaWorkerKiller.config do |config|
config.ram = 1024 # mb
config.frequency = 5 # seconds
config.percent_usage = 0.98
config.rolling_restart_frequency = 12 * 3600 # 12 hours in seconds
end
PumaWorkerKiller.start
end
What is happening here is basically you have several versions of the gem in your system.
Most of the time it did not cause issues because bundle exec will dynamically load required versions for your application.
In some cases gems will have binary files included. It such case bundle exec will not help because you can have only one version linked in one moment.
Basically, if you want to call the binary by alias you have to use separate gemset for each application.
If you want to keep all the gems in one place you can call binary files directly.
In your case it will be:
RAILS_ENV=dev3 bundle exec pumactl _0.1.0_ -F ./config/puma.rb
The _<version>_ construction allows you to specify version of the binary file you want to run.
You can create your custom binary as well, like fake_pumactl inside the project which will check the Gemfile.lock and automatically proxy your call to the library and specify version automatically for you. Another way is to parse gem version by shell script and put this script instead of _<version>_ in your call.
Here is the brief example
$ gem install puma
Fetching puma-4.3.3.gem
$ gem install puma -v 4.3.0
Fetching puma-4.3.0.gem
$ pumactl -v
4.3.3
$ pumactl _4.3.0_ -v
4.3.0
$ ruby -v
ruby 2.6.3p62
$ export puma_version=_4.3.0_
$ pumactl ${puma_version} -v
4.3.0
puma_version variable can be defined from result of a bash command which will extract the gem version from Gemfile.lock.

How to delete a gem so that I don't need to prepend bundle exec for rails commands?

If I try to run tests I get
Gem::LoadError: You have already activated jruby-openssl 0.9.5, but your Gemfile requires jruby-openssl 0.8.5. Prepending bundle exec to your command may solve this.
I can do as indicated and prepend bundle exec to get around this.
This is happening because I have a newer version of the gem in another project.
However I am no longer using the other application with the newer version of the gem, so I was wondering:
How can I actually remove the newer version so I don't have to bundle exec before my rails commands?
You can delete a gem (or a specific version of a gem) by running
gem uninstall <gem_name>
If there's multiple versions then a prompt will ask which version to remove.
Use gem uninstall with the -v switch to specify a version to uninstall:
gem uninstall jruby-openssl -v 0.9.5
Depending on your OS and shell, you could create an alias or function for the command (I’m guessing this is using Rake).
For example I have this in my .bashrc
function bake {
bundle exec rake "$#"
}
So now I can type bake whatever and the command that is run is bundle exec rake whatever.
This usually happens when you are 'polluting' the global gemset using it for different projects.
A good way to isolate gemsets is to use rvm. Once installed, you can create a file per project named .ruby-version with a single line on it that identifies the gemset with the syntax <ruby version>#<your project>. From the console:
$> echo "2.1#myproject" > .ruby-version
$> cd .
This will create a gemset for your project and everytime you enter the root directory, the gemset will be specific to this project. Then you could have different gem versions for different projects and run rake (or any other command) just fine without messing dependencies.

Rails - the newest gem is installed but the applicaiton is old

I'm working on Bluehost. I installed the 3.2.8 gem of rails, and now I get this:
> gem list --local | grep rails
rails (3.2.8)
But:
rails --version
Rails 2.3.11
How can I make the "rails" command use the latest gem? I guess it has something to do with my $PATH variable but I'm pretty much clueless about it.
Also, the gem and rails command give rise to some errors that look like this:
Invalid gemspec in [XXX]: invalid date format in specification: "YYY"
I'm not sure if that's connected (and I'm wondering what causes such errors anyway).
Try running this command:
curl -L https://get.rvm.io | bash -s stable --ruby --rails
What it does is install RVM, which maintains separate gems for each version of Ruby installed. The --ruby and --rails arguments tell it to install ruby and rails while installing RVM. RVM installation automatically updates $PATH and any other necessary environment variables.
At the end of installation, it should prompt you to run:
source ~/.rvm/scripts/rvm
which will make those environment variable changes effective immediately. Alternatively, you can log out and then log right back in.
Run rails -v and ruby -v at that point, and you should see them pointing to the new version. Run bundle install from your RoR app's directory and all the gems you need should install in ~/.rvm/gems/ruby-/gems.
At that point, you can delete/uninstall any gems/rails/ruby from before installing RVM.
EDIT on 10/17/2012:
Nevermind my answer. Even though it might be possible to get Rails 3.x running with the currently installed Ruby 1.8 (see this Stackoverflow question), you won't be able to run Ruby 1.9.x using Bluehost Shared Hosting. Your only choice (for now) is VPS Hosting.
The reason is that Passenger Phusion is tied to the version of Ruby installed in /usr/lib, which you can't change without root access. Even though you can install any version of Ruby with RVM, you won't get Passenger to talk to it and therefore your rails project won't use its gems.

Accessing localhost server for Rails

I am trying to teach myself ruby on rails and I when I tried to access my server using Terminal on my Mac this is what I got back:
rails server /Library/Ruby/Site/1.8/rubygems/dependency.rb:247:in
to_specs': Could not find railties (>= 0) amongst [bundler-1.0.22,
rake-0.9.2] (Gem::LoadError) from
/Library/Ruby/Site/1.8/rubygems/dependency.rb:256:into_spec' from
/Library/Ruby/Site/1.8/rubygems.rb:1208:in `gem' from
/usr/bin/rails:18
Any thoughts on this?
Try typing "bundle exec rails server" to ensure that the proper gems are being loaded.
Also you'll probably want to be using Ruby 1.9.x for new Rails apps. Since you're using OS X I suggest https://github.com/sstephenson/ruby-build to build the latest version of Ruby. You can use it in conjunction with rbenv which will help you manage having two versions of Ruby on the same system.
If you do decide to use rbenv you'll want to type "gem uninstall bundler" and then reinstall it after you install rbenv so that the gem bin is in the right place. As stated above, you'll want to use "bundle exec" before any rails or rake command to make sure the proper environment is loaded.

Rails keeps telling me that it's not currently installed

I use rvm to manage different rubies and their gemsets. My shell is zsh with oh-my-zsh configured with basic settings. Enabled oh-my-zsh plugins are ruby, rails, osx, and git. Here's the command I used to install ruby-1.8.7 and rails-3.0.7.
rvm install 1.8.7
rvm use 1.8.7
gem install rails -v=3.0.7
and then I typed rails and got:
Rails is not currently installed on this system. To get the latest version, simply type:
$ sudo gem install rails
You can then rerun your "rails" command.
I've tried more thorough installs also, Like reinstall rubygems after switching to ruby-1.8.7, or create a completely new gemset, but with no luck.
Here's the rvm info:
ruby-1.8.7-p352#rails:
system:
uname: "Darwin yicai.local 10.8.0 Darwin Kernel Version 10.8.0: Tue Jun 7 16:32:41 PDT 2011; root:xnu-1504.15.3~1/RELEASE_X86_64 x86_64"
bash: "/bin/bash => GNU bash, version 3.2.48(1)-release (x86_64-apple-darwin10.0)"
zsh: "/bin/zsh => zsh 4.3.9 (i386-apple-darwin10.0)"
rvm:
version: "rvm 1.8.6 by Wayne E. Seguin (wayneeseguin#gmail.com) [https://rvm.beginrescueend.com/]"
ruby:
interpreter: "ruby"
version: "1.8.7"
date: "2011-06-30"
platform: "i686-darwin10.8.0"
patchlevel: "2011-06-30 patchlevel 352"
full_version: "ruby 1.8.7 (2011-06-30 patchlevel 352) [i686-darwin10.8.0]"
homes:
gem: "/Users/nil/.rvm/gems/ruby-1.8.7-p352#rails"
ruby: "/Users/nil/.rvm/rubies/ruby-1.8.7-p352"
binaries:
ruby: "/Users/nil/.rvm/rubies/ruby-1.8.7-p352/bin/ruby"
irb: "/Users/nil/.rvm/rubies/ruby-1.8.7-p352/bin/irb"
gem: "/Users/nil/.rvm/rubies/ruby-1.8.7-p352/bin/gem"
rake: "/Users/nil/.rvm/bin/rake"
environment:
PATH: "/Users/nil/.rvm/gems/ruby-1.8.7-p352#rails/bin:/Users/nil/.rvm/gems/ruby-1.8.7-p352#global/bin:/Users/nil/.rvm/rubies/ruby-1.8.7-p352/bin:/Users/nil/.rvm/bin:/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin:/usr/X11/bin:/usr/local/sbin"
GEM_HOME: "/Users/nil/.rvm/gems/ruby-1.8.7-p352#rails"
GEM_PATH: "/Users/nil/.rvm/gems/ruby-1.8.7-p352#rails:/Users/nil/.rvm/gems/ruby-1.8.7-p352#global"
MY_RUBY_HOME: "/Users/nil/.rvm/rubies/ruby-1.8.7-p352"
IRBRC: "/Users/nil/.rvm/rubies/ruby-1.8.7-p352/.irbrc"
RUBYOPT: ""
gemset: "rails"
and the gem version is 1.8.10, the latest.
If you're running a rails command immediately after installing rails, you will need to restart your terminal before your commands will be recognized.
I had this problem today. Not completely related to your question, but since this page is what comes up in Google when I search for "Rails is not currently installed on this system", I thought I would add my answer:
What happened is that I was using ruby 1.9.2 with rails for a while, but then I needed to use ruby 1.8.7 to run some other script that I found.
Afterwards, I wanted to change by system back to using 1.9.2, and that's where the problem started:
$ rvm list
=> ruby-1.8.7-p352 [ x86_64 ]
ruby-1.9.2-p290 [ x86_64 ]
$ rvm use 1.9.2
I thought that would do the trick. But no, that gives me the "Rails is not currently installed on this system" message.
What I had forgotten is that I had configured rails using an rvm gemset. So I needed to specify the correct gemset when I was selecting which ruby version to make active.
$ rvm gemset list_all
gemsets for ruby-1.8.7-p352 (found in /Users/asgeo1/.rvm/gems/ruby-1.8.7-p352)
global
gemsets for ruby-1.9.2-p290 (found in /Users/asgeo1/.rvm/gems/ruby-1.9.2-p290)
global
rails31
$ rvm use ruby-1.9.2-p290#rails31
That did the trick.
Mac OS X, rbenv, and rails
I was getting the exact same issue but with rbenv rather than rvm. After verifying a correct .bash_profile.
.bash_profile
export PATH="$HOME/.rbenv/bin:/usr/local/bin:$PATH"
eval "$(rbenv init -)"
Restart the shell
exec $SHELL -l
Check the path
echo $PATH
Finally
I repeatedly installed and uninstalled rails but it was never placed in the .rbenv/bin directory after rbenv rehash. In the end I did a find . -name rails and uninstalled every gem that was returned and uninstalled rails. Then:
$ gem install rails
$ rbenv rehash
$ which rails
/Users/palmerc/.rbenv/shims/rails
I had the same issue and found that RVM was not showing as installed either if I tried the rvm command. All it took to fix both problems was running this command in the terminal
$ source ~/.rvm/scripts/rvm
Restart your terminal and then re-run your rails command
Rails is not reporting that it isn't installed. Your Debian system is telling you that rails isn't installed. One thing about rvm is that it relies on some complicated bash shell scripting and you sometimes need to start a fresh shell for changes to appear. You should also make sure that the correct rvm shell commands were added to your .zshrc file.
Also check your path to make sure the ~/.rvm/gems/... path in included.
I ran into this issue using rbenv. Turns out gem install rails did in fact install Rails but rails was not recognized as an executable. The fix for me was to run rbenv rehash.
I found this fix and more details on setting up Rails 5 at https://gorails.com/setup/osx/10.11-el-capitan
I have encountered this problem, but it has been resolved.
I use macOS, I do not use rvm, I only use HomeBrew, I first use gem env to get the installation directory of all gems, mine is:
$ gem env
RubyGems Environment:
   -RUBYGEMS VERSION: 3.1.2
   -RUBY VERSION: 2.7.1 (2020-03-31 patchlevel 83) [x86_64-darwin19]
   -INSTALLATION DIRECTORY: /usr/local/lib/ruby/gems/2.7.0
   -USER INSTALLATION DIRECTORY: /Users/myname/.gem/ruby/2.7.0
...
Then you try to go to /usr/local/lib/ruby/gems/2.7.0 to find the executable file directory of the rails gem that you have installed, for example: /usr/local/lib/ruby/gems/2.7.0/bin, then add to the path environment variable
I found this problem but the solutions above didn't solve it. I am not using rvm (and I'm working on mac) and I had to update the path to add rails executable directory:
echo 'export PATH="/usr/local/lib/ruby/gems/3.0.0/bin:$PATH"' >> ~/.zshrc
I had a similar issue, but with rbenv.
I originally installed ruby on bash. Then I played around with .bashrc in VIM, messed that file up, and reset it back to default. In doing so, I unknowingly removed the exported rbenv $PATH. Because of this, my terminal no longer recognized that I had ruby installed.
I revisited the ruby installation page (https://gorails.com/setup/ubuntu/15.04) and tried to set up my rbenv path again with this command:
echo 'export PATH="$HOME/.rbenv/bin:$PATH"' >> ~/.bashrc
It failed.
Luckily, I had already switched to zsh (with oh-my-zsh) between the time I messed up my .bashrc and the time I tried to access irb from my terminal.
My solution was to set up the rbenv path per the installation guide, but by replacing all instances of .bashrc with .zshrc like so:
echo 'export PATH="$HOME/.rbenv/bin:$PATH"' >> ~/.zshrc
Hope this helps!
Here's what I've done. And the problem is gone. Hence I guess problem solved.
rvm use system
change to the system ruby. remove all gems in it using the command provided and explained here. then I install wanted ruby versions from scratch:
rvm install 1.8.7
rvm install rails -v 3.0.7
then bundle install
for further detail, might need dig into the gem install procedure.
add source ~/.rvm/scripts/rvm to your .bashrc file if rails installs fine but then you get the error "rails is not currently installed". This frustrated me for a while but I found the answer here: http://www.codelearn.org/blog/how-to-install-ruby-rails-screencasts-linux-mac-windows
I just reloaded my terminal
source ~/.bashrc
See: How do I reload .bashrc without logging out and back in?
Rbenv users
I had the same issue and this worked for me.
Setting the ruby version in the current directory.
rbenv local 2.7.1
Then I was able to run rails new
I had the same problem but the solution above didn't help.
This was my scenario
rvm list
=> ree-1.8.7-2012.02 [ i686 ]
ruby-1.9.3-p125 [ x86_64 ]
which ruby
/Users/dev/.rvm/rubies/ree-1.8.7-2012.02/bin/ruby
which rails
/usr/bin/rails
gem list --local
..
rails (3.2.8)
rails2_asset_pipeline (0.1.20)
railties (3.2.8)
..
rvm use ruby-1.9.3-p125
which ruby
/Users/dev/.rvm/rubies/ruby-1.9.3-p125/bin/ruby
which rails
/Users/dev/.rvm/gems/ruby-1.9.3-p125/bin/rails
By uninstalling rails and railties and reinstalling rails when using ree my problem was resolved.
Hope this helps others in my situation, not sure how I got into it :S
I had the same problem, I ended up deleting my .rvmrc rvm --create --rvmrc 1.8.7#project where the 1.8.7#project is whatever you want your ruby to be. cded in and out and it worked. http://sirupsen.com/get-started-right-with-rvm/
Just had same problem and couldn't find an answer. Here's what I did:
find current rails path
$ which rails
returns something like this: /usr/local/rails
Delete current version:
$ sudo rm -rf /usr/local/rails
Reinstall rails
$ sudo gem install rails
I ran into this same issue and none of the answers given helped so I thought I'd share my solution in case it might be useful for someone else.
I was messing around with my .profile and .bashrc files and along the way I messed up my RVM install. Still not sure exactly what I did, but the fix was easy. Just had to run the following command, which cleans up all of your system path settings for RVM:
rvm get [head|stable] --auto-dotfiles
Note that if you're running an old version of RVM this may upgrade your setup, which may not be what you want.
A possible solution is to not maintain two different configuration files .bash_profile and .bashrc
The solution as suggested in this excellent post on the difference between .bash_profile and .bashrc is to source .bashrc from your .bash_profile file, then putting PATH and common settings in .bashrc.
Quoting,
add the following lines to .bash_profile:
if [ -f ~/.bashrc ]; then
source ~/.bashrc
fi
end quote
I had this error after updating ruby. I had to run 'bundle install' to fix it.
Try to specify gemset explicitely in your Gemfile:
source 'https://rubygems.org'
ruby "2.2.3"
#ruby-gemset=rails424
Try This:
You need to change your terminal emulator preferences to allow login shell.
Sometimes it is required to use /bin/bash --login as the command.
$ bin/bash --login
$ rails -v
I had this message on my Mac:
Rails is not currently installed on this system. To get the latest
version, simply type:
and it was about the $PATH not being correct. The system has an outdated version of rails (/usr/bin/ruby). The path to your chosen version of ruby ($HOME/.rbenv/versions/2.3.0/bin) must precede the system's outdated version along $PATH var, like below:
export PATH="$HOME/.rbenv/versions/2.3.0/bin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:$PATH"
adjust it to your version of ruby.
For MacOS (High Sierra):
Tokaido is the Rails installer system recommended on the "Getting Started" Rails guide page for Mac OS. But it doesn't just install, it runs its own shell scripts. If you start out using that, which sources its own shell environment, then later start a terminal without launching from the Tokaido shell, this happens, because the "rails" command falls back to the original system rails code on the Mac.
For mine, the 'which rails' command in a normal terminal returns
/usr/bin/rails
But after launching Tokaido's shell, 'which rails' gives this path:
/Users/charlesross/.tokaido/Gems/2.2.0/bin/rails
Out of nowhere Rails wasn't currently installed but, what fixed it was
rvm use ruby-2.6.0
...and verified my path in .bash_profile
export PATH="$PATH:$HOME/.rvm/bin"
I was having this problem today. I haven't 100% solved it, but in new tabs I can do rvm use 2.5.5 and then rails -v works fine.
➜ my-repo git:(next_release) ruby -v
ruby 2.5.5p157 (2019-03-15 revision 67260) [x86_64-darwin18]
➜ my-repo git:(next_release) rails -v
Rails is not currently installed on this system. To get the latest version, simply type:
$ sudo gem install rails
You can then rerun your "rails" command.
➜ my-repo git:(next_release) rvm use 2.5.5
Using /Users/amberwilkie/.rvm/gems/ruby-2.5.5
➜ my-repo git:(next_release) rails -v
Could not find rake-12.3.3 in any of the sources
Run `bundle install` to install missing gems.
➜ my-repo git:(next_release) bundle install
I was looking through the source and found another error message that suggested the user run the following command.
I ran the command and everything now works. None of the suggestions above worked for me. Run the command from inside your newly created Rails app.
gem pristine --all
Here is how it worked for me:
Intall rvm in mac by following the mac installation instruction
rvm install ruby
gem install rails
rails --version
For me ( MacOS Monterey, rbenv) adding rails version to gem install command get the problem resolved.
you can find a specific version of rails that matches to your ruby from this link and replace the VERSION .
gem install rails -v VERSION
rbenv rehash
after successful installation, then rails should be added to /Users/your_user/.rbenv/shims
Also plz check that your shims directory should be the first element of your path.
➜ ~ echo $PATH #
/Users/ario/.rbenv/shims: ...
I was following along with the Odin Project ruby-on-rails course by
installing rbenv,
adding eval "$(rbenv init -)" to ~/.zshrc
installing rails gem
attempting to run rails new my_first_rails_app
But I had forgot to run source ~/.zshrc after editing the file, so I was seeing the error:
Rails is not currently installed on this system.

Resources