RVM + rails 4 + whenever =? - cron

as the title suggests I am running
rails 4
Ruby 1.9.3-p0
rvm 1.6.9
whenever 0.8.3
the project's gemset
I run whenever -w and get the appropriate setting in the crontab.
If I copy & paste that command all works out well.
Cron however has other opinion.
I tried following advice here http://danielsz.github.io/how-to-run-rvm-scripts-as-cron-jobs/index.html/ , but without much success.
Looks to me that cron fails to set the appropriate gemset.
How can I fix this?
thanks!

First of all RVM 1.6.9 is very old version, you should update with
rvm get head
rvm reload
rvm get stable
But I'm afraid you might be using ruby-rvm package from ubuntu repositories, you should use then this answer https://stackoverflow.com/a/9056395/497756 (yes this is necessary).
As for integration with cron - use wrappers and aliases:
rvm alias create my_app 1.9.3#my_app
rvm wrapper my_app --no-prefix --all
This assumed your application gems are installed in 1.9.3#my_app, it created an alias my_app so it can be referenced in scripts so the scripts do not need to be changed when new ruby version is used.
The wrappers were created in /path/to/rvm/wrappers/my_app/* this are binary files automatically loading proper ruby environment for your application, they can be used in two ways:
export PATH=/path/to/rvm/wrappers/my_app:$PATH and then simply call bundle rake
call directly: /path/to/rvm/wrappers/my_app/bundle rake
If you use rvm-capistrano it has a command to do the wrappers and alias creation for you => https://github.com/wayneeseguin/rvm-capistrano#create-application-alias-and-wrappers

Related

How to change my version of node using a script?

I'm trying to write scripts that allow me to switch my development environment.
I want to write a script so that I can call it like this:
switchdevA
and inside that script, one of the things it should do is switch to node v16.16.0
inside switchdevA i have the following:
#!/bin/zsh
source ~/.zshrc
nvm use v16.16.0
the output says that I have switched to node v16.16.0, but when I type node -v I get:
v12.22.12
I can fix if i call source switchdevA, but should I do it that way? Other things like java don't seem to require me sourcing. In addition, the installation is lost if I start a new zsh session, ideally it should install for the current session and all future sessions.
What's the best practice around this?
A quick clarification: NVM is a shell function and not an executable.
You've correctly identified that source switchdevA will work properly, and that it is different from other version managers.
One solution is to keep your script as is, and create an additional shell alias that will run source scriptname (e.g. alias switchdevA='source switchdevA').
Unfortunately, for your other request to keep the current Node version in all future shell sessions, that can’t be achieved unless you have some persistence added in. For example, a simple file named ~/.lastnode. Then, in your ~/.zshrc, you would have a line nvm use "$(cat ~/.lastnode)" (which comes after the initialization of NVM). Finally, the original script would need to include a line at the bottom to update the last selected Node version: nvm version > ~/.lastnode.

"Warning! PATH is not properly set up" & "RVM is not a function" after Heroku toolbelt installation

I am on Ubuntu 14.04 LTS.
I installed rvm + ruby + rails and restarted the machine.
Everything was working fine until I installed the Heroku toolbet.
When I decided to create a new project-specific gemset with rvm use ruby-2.2.1#new_app --ruby-version --create, I received this message:
Warning! PATH is not properly set up, '/home/mark/.rvm/gems/ruby-2.2.1/bin' is not at first place,
usually this is caused by shell initialization files - check them for 'PATH=...' entries,
it might also help to re-add RVM to your dotfiles: 'rvm get stable --auto-dotfiles',
to fix temporarily in this shell session run: 'rvm use ruby-2.2.1'.
RVM is not a function, selecting rubies with 'rvm use ...' will not work.
You need to change your terminal emulator preferences to allow login shell.
Sometimes it is required to use /bin/bash --login as the command.
Please visit https://rvm.io/integration/gnome-terminal/ for an example.
I receive the "Warning! PATH is not properly set up" warning every time I use a rvm command, such as rvm list for instance.
The output of echo $PATH is:
/usr/local/heroku/bin:/home/mark/.rvm/gems/ruby-2.2.1/bin:/home/mark/.rvm/gems/ruby-2.2.1#global/bin:/home/mark/.rvm/rubies/ruby-2.2.1/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/home/mark/.rvm/bin:/home/mark/.rvm/bin:/home/mark/.rvm/bin:/home/mark/.rvm/bin
As you can see /usr/local/heroku/bin is at first place instead of /home/mark/.rvm/gems/ruby-2.2.1/bin, and this is probably causing the issue.
I suppose it would be better if /usr/local/heroku/bin were after all the rvm paths.
My .bash_profile looks fine:
[[ -s "$HOME/.profile" ]] && source "$HOME/.profile" # Load the default .profile
[[ -s "$HOME/.rvm/scripts/rvm" ]] && source "$HOME/.rvm/scripts/rvm" # Load RVM into a shell session *as a function*
The last lines of my .bashrc file are:
export PATH="$PATH:$HOME/.rvm/bin" # Add RVM to PATH for scripting
### Added by the Heroku Toolbelt
export PATH="/usr/local/heroku/bin:$PATH"
export PATH="$PATH:$HOME/.rvm/bin" # Add RVM to PATH for scripting
export PATH="$PATH:$HOME/.rvm/bin" # Add RVM to PATH for scripting
I tried to run rvm get stable --auto-dotfiles (and rvm get head --auto-dotfiles as suggested in Warning! PATH is not properly set up, usually this is caused by shell initialization files) without results.
I would change the order of the paths in $PATH and move Heroku to a more convenient place if possible and if I knew how to do it.
What would you suggest?
Matthew Cullum's solution in RVM Warning! PATH is not properly set up solved my issue. It seems also that for rvm to work properly it is necessary that the respective line of code in ~/bashrc be the last.

Can't run heroku or vagrant in cygwin, but OK in cmd

Somehow, I can't run vagrant or heroku in cygwin. It works fine when I'm using the default windows cmd application, but in cygwin, I get this error for vagrant:
C:/vagrant/vagrant/embedded/lib/ruby/site_ruby/1.9.1/rubygems/dependency.rb:247:in to_specs': Could not find vagrant (>= 0) amongst [] (Gem::LoadError) from C:/vagrant/vagrant/embedded/lib/ruby/site_ruby/1.9.1/rubygems/dependency.rb:256:into_spec' from C:/vagrant/vagrant/embedded/lib/ruby/site_ruby/1.9.1/rubygems.rb:1231:in gem' from C:/vagrant/vagrant/embedded/gems/bin/vagrant:22:in'
And for heroku:
C:\Program Files (x86)\ruby-1.9.2\bin\ruby.exe: No such file or directory -- /cygdrive/c/Program Files (x86)/Heroku/bin/heroku (LoadError)
What is this thing about ruby? I have no idea what I should be doing - developing in windows is a real pain, can anyone provide any insight into how I might solve this problem?
Appreciate any help. Thanks!
I ran in the same problem using Rails and Heroku on Windows.
It seems that the Toolbelt is not supported under Cygwin. Moreover colors are not always rendered in the right way (for example, I did not manage to render heroku logs colors, even after using ansicon -i).
I also considered using the CMD Prompt augmented with GOW but that means you have to append ".bat" to every command, and colors are still a problem.
I ended up using the Git Bash shell that is included with the RailsInstaller package.
It recongnizes all paths to relevant files, it has all the shell commands you need, and every color seems to be rendered correctly (e.g. rails logs, cucumber and rspec tests, heroku logs, etc.).
You've probably solved your issue a long time ago but I just wanted to add the steps I went through as I had the same issue on Windows with Cygwin.
Firstly always try to do an update of your Cygwin installation especially when you see an error similar to the one you've posted (I had the same error):
/ruby: No such file or directoryin/heroku: line 4: /cygdrive/d/Development/Heroku/ruby-1.9.2/bin
So I updated Cygwin and made sure to select all necessary ruby packages/interpreters etc, but this still didn't solve the problem as I kept getting the same error message.
Then I followed the steps outlined in Running the Heroku Command-Line Client Under Cygwin:
(1) Download RubyGem 1.9.3 from
http://rubyforge.org/frs/download.php/76072/rubygems-1.8.24.zip
(2) Then run the following -
$ unzip rubygems-1.8.24.zip
$ cd rubygems-1.8.24/rubygems-1.8.24
$ ruby setup.rb install
$ gem update --system
$ gem install heroku
(3) Open a new shell window and verify the version -
$ heroku version
heroku-gem/2.28.10 (i386-cygwin) ruby/1.8.7
This solved my problem and I can now run heroku commands from the Cygwin shell on Windows.
For me #Azkuma's answer only got me half the way. What worked for me:
1) Download and extract RubyGem zip: https://rubygems.org/pages/download
2) Set aliases to gem and heroku
alias gem='C:/ruby/bin/gem'
alias heroku='"C:/Program Files (x86)/Heroku/bin/heroku.bat"'
3) install as above
ruby setup.rb install
gem update --system
gem install heroku
4) login to heroku
heroku login
I found simply setting an alias worked for me.
alias heroku=c:/Program\\\ Files\\\ \\\(x86\\\)/Heroku/bin/heroku.bat
Then I can just use the heroku command directly with Cygwin.
The only thing I have a problem with is heroku login (and by extension, git push heroku master) whereby I'm prompted to use cmd.exe. For that part, I just open my Git Bash window from within the relevant folder, login and push from there.

rvm & duplicate environment variables (rubymotion)

I think I have a gem installed twice but I don't know how to uninstall one of them. When I try to build my rubymotion project I get these warnings:
/Users/pachun/.rvm/gems/ruby-1.9.3-p194#global/gems/bundler-1.2.1/lib/Bundler.rb:12: warning: already initialized constant ORIGINAL_ENV
/Users/pachun/.rvm/gems/ruby-1.9.3-p194#global/gems/bundler-1.2.1/lib/Bundler.rb:64: warning: already initialized constant WINDOWS
/Users/pachun/.rvm/gems/ruby-1.9.3-p194#global/gems/bundler-1.2.1/lib/Bundler.rb:65: warning: already initialized constant FREEBSD
/Users/pachun/.rvm/gems/ruby-1.9.3-p194#global/gems/bundler-1.2.1/lib/Bundler.rb:66: warning: already initialized constant NULL
And regular builds still work, but I think this is causing my test suite (frank cucumber) to fail.
How can I fix this? Thanks
The easiest way to remove all gems and reinstall using rvm is do this:
rvm gemset empty <gemset name>
bundle
Instead of doing that, I would recommend you make a .rvmrc file and put the following:
rvm use 1.9.3#projectname --create
Save the file to your project folder and then cd out and back in to the folder, answering "Y" to the question of whether to load the .rvmrc file. This will switch you to a new (empty) gemset and you can re-run bundle.

Linux automatically environment variables set?

I installed libffi-3.0.11, because another program needs that. But after the installation the other program (by calling the comand ./configure)don't recognize that libffi is installed. Do I have to set a environment variable? Or are all variables set automatically?
usually there is a LIBPATH, you should try to include the directory where your lib resided into this path. In addition, if you have a default bash
export LIBPATH=/your/libffi/path:$LIBPATH
I highly recommend to put this into a script and load it whenever you login automatically so that you don't need to repeat this step
/home/yourhome/.profile <- make sure you insert it into this file and its loaded automatically
Here is a guide how to do the task:
http://archive.linuxfromscratch.org/lfs-museum/5.1-pre1/LFS-BOOK-5.1-PRE1-HTML/chapter06/glibc.html
The parameter you probably need is the following:
./configure --libexecdir=/usr/lib:
If you have installed the libffi library properly this should completely solve your problem.
It depends, if you install libffi on /usr/local you should probably set the includes dir of the app you want to configure to /usr/local.
For the new app, try ./configure --prefix=/usr/local. To see the options of configure, use ./configure --help. Can you show the example of what is not running ?

Resources