I have a Windows10 Ubuntu bash environment set up. It has a few rubygems installed (without docker, bundler, without rvm, and also this is not rails). The script is working fine when I run it manually from inside the Ubuntu terminal, in the user home folder ~/
Now my goal is create a Windows Scheduled Task using the Task Scheduler application, to run the script daily, like I would with a crontab in Unix.
The action in this Scheduled Task is the challenge. In testing manually from the Windows CMD prompt, I got as far as:
C:\>C:\Windows\System32\bash.exe -c "ruby ~/myscript.rb"
That fails :
Traceback (most recent call last):
2: from /home/lam/ruby/remind_prepare_dad_before_iterative_ends.rb:15:in `<main>'
1: from /usr/lib/ruby/2.5.0/rubygems/core_ext/kernel_require.rb:59:in `require'
/usr/lib/ruby/2.5.0/rubygems/core_ext/kernel_require.rb:59:in `require': cannot load such file -- tiny_tds (LoadError)
Above error tells me it cannot find my gem, TinyTDS. What do I add to the command line to make it find my gems?
I found a crude workaround for my own problem: just install the gem from the same command line:
C:\>C:\Windows\System32\bash.exe -c "sudo gem install tiny_tds"
I had to re-install a few more gems I use in the same way.
After this, I put in a -C argument to start ruby in the right directory, like so:
C:\>C:\Windows\System32\bash.exe -c "ruby -C ~/ruby myscript.rb"
works like a charm.
I suppose now I have duplicated gems floating in spaces on the machine, but we will address that issue if it ever becomes a problem. :-)
Try bundle exec ruby ~/myscript.rb
Related
I have searched through the slack forums and nothing seems to be working for my instance!
A little background; I am working with a Angular1, Heroku-Postgresql, Nodejs, Ruby&Rails application. Previously developed by someone else and has been passed down to me.
When I run in Windows Powershell
heroku rake db:migrate -a [app]
my console returns
Running rake db:migrate on [app]... up, run.7474 (Free) bash: rake: command not found
I have tried "heroku run rake db:migrate", does not work.
Installed bash on ubuntu on windows, added appropriate gem files, heroku, etc. created a symbolic link sudo ln -s /var/lib/gems/1.8/bin/rake
& still get bash: rake: command not found
Tried to run rake inside the heroku bash shell, and still get 'not found'.
Updated gemfiles, ruby files, added ruby bin to my environment variables.
So what gives? I am not familiar with Bash Ubuntu. Any guidance on what steps to take/try would be tremendous help.
You're running that command on heroku platform.
And, as seen on documentation, you should run your command as
heroku run rake db:migrate -a [appname]
My guess would be that you have something in some script that tries to execute rake.
You can use the --trace argument to see the detailed execution.
Ruby newbie.
How do I run ruby from Sublime Text -3 which are running fine from terminal but giving error in ST as mentioned below -
I had Ruby 1.9.x installed and Sublime Text-3 was able to run ruby files with Shift+Ctrl+B.
Then I upgraded to 2.1.2, followed steps from the article about it to install gems, update path and all. Now my ruby files are running fine when I trigger them from terminal. But when I try to run from ST-3 I get:
/usr/local/lib/ruby/2.1.0/rubygems/core_ext/kernel_require.rb:55:in `require': cannot load such file -- watir-webdriver (LoadError)
from /usr/local/lib/ruby/2.1.0/rubygems/core_ext/kernel_require.rb:55:in `require'
from /home/xxx/UI_Automation/spec/basic_test.rb:1:in `<main>'
[Finished in 0.0s with exit code 1]
[shell_cmd: ruby "/home/xxx/UI_Automation/spec/basic_test.rb"]
[dir: /home/techdigita/UI_Automation/spec]
[path: /usr/lib/lightdm/lightdm:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games]
Note: The same program runs from terminal. And like I said I am so knew to Ruby I just followed steps to update GEM_PATH, GEM_HOME etc without thinking much. I had updated from 1.8 to 1.9 without any such issue. Thanks in anticipation.
When I need to run a script from my linux user "user1", I do the following commands (right after login with "user1"):
rvm use 1.9.3
cd /var/proj
ruby main.rb
When developing this script, I have created a bundle with bundle install, reading my Gemfile (containing httparty and other stuff).
This is working fine (no reason it would not work :) )
When I log with another user "user2", I'd like to execute the script but cannot have it working:
cd /var/proj
/home/user1/.rvm/rubies/ruby-1.9.3-p327/bin/ruby main.rb
The error I get:
/home/user1/.rvm/rubies/ruby-1.9.3-p327/lib/ruby/site_ruby/1.9.1/rubygems/custom_require.rb:36:in `require': cannot load such file -- httparty (LoadError)
from /home/user1/.rvm/rubies/ruby-1.9.3-p327/lib/ruby/site_ruby/1.9.1/rubygems/custom_require.rb:36:in `require'
from main.rb:3:in `<main>'
It seems it cannot see the bundle created by the other user. Any idea of what needs to be changed ?
I'd like to run this script within supervisor but this is the same thing.
It is not the recommended but you can use RVM from other a/c . Just set the rvm required path in another user a/c.
Details instruction:
First go to user1 and follow this steps
rvm use 1.9.3
echo $PATH
now copy the path which include rvm word , in my case it is
/home/paritosh/.rvm/gems/ruby-1.9.3-p194/bin:/home/paritosh/.rvm/gems/ruby-1.9.3-p194#global/bin:/home/paritosh/.rvm/rubies/ruby-1.9.3-p194/bin:/home/paritosh/.rvm/bin
now go to another user2 a/c and use PATH=copied_path:$PATH so in my case it is
PATH=/home/paritosh/.rvm/gems/ruby-1.9.3-p194/bin:/home/paritosh/.rvm/gems/ruby-1.9.3-p194#global/bin:/home/paritosh/.rvm/rubies/ruby-1.9.3-p194/bin:/home/paritosh/.rvm/bin:$PATH
Now go to
cd /var/proj
ruby main.rb
btw, if you want to make the path permanent put the PATH in ~/.bashrc of user2 a/c .
I have installed ruby and gems with sudo,
Whenever I run the script, I have to do it with sudo or else I will get this error:
/usr/local/rvm/rubies/ruby-1.9.3-p385/lib/ruby/site_ruby/1.9.1/rubygems/custom_require.rb:36:in `require': cannot load such file -- watir-webdriver (LoadError)
from /usr/local/rvm/rubies/ruby-1.9.3-p385/lib/ruby/site_ruby/1.9.1/rubygems/custom_require.rb:36:in `require'from Login.rb:1:in `<main>'
I am planning to use eclipse IDE, so--if I do run the script in eclipse--I get the same problem
Could someone help me in running ruby script as superuser in eclipse?
You can change the access permissions for needed gem.
sudo chmod 644 filename
To know the full path:
gem which gemname
I'm absolute newbie in Ruby and Rails project, so I'm sorry if this is dumb question.
I've installed heroku toolbelt using wget -qO- https://toolbelt.heroku.com/install-ubuntu.sh | sh. Also I tried gem install heroku. But when I type:
MY_USER#home-PC:~$ heroku version
<internal:gem_prelude>:1:in `require': cannot load such file -- rubygems.rb (LoadError)
from <internal:gem_prelude>:1:in `<compiled>'
I've checked in google and people suggest that gem and current ruby are different versions so I've checked it and they seem to the same:
MY_USER#home-PC:~$ which ruby
/home/MY_USER/.rvm/rubies/ruby-1.9.3-p327/bin/ruby
MY_USER#home-PC:~$ gem env | grep 'RUBY EXECUTABLE'
- RUBY EXECUTABLE: /home/MY_USER/.rvm/rubies/ruby-1.9.3-p327/bin/ruby
I have no idea what to do more, so please help.
Sorry for the maybe stupid question, thanks in advance.
EDIT:
Forgot to say I'm running Ubuntu 12.10.
The problem is that the heroku executable you installed probably starts with a line like this:
#!/usr/bin/ruby
This will force the heroku command to always use the system-wide ruby (/usr/bin/ruby) and it will never run your rvm version of ruby.
To fix it simply edit the first line of the heroku script to this:
#!/usr/bin/env ruby
This will make the heroku command run whichever ruby command is in the current PATH, instead of a hard coded path like previously.
To find the location of the heroku script, so you can edit it, simply type:
which heroku
It should print out the location of the script so you can find it and load it into your editor.
Also if you do not have write permission you may enter:
:w !sudo tee % > /dev/null
to save successfully .