rubys> cd command not working in command line - ruby-on-rails

I'm just getting into ruby and am trying to execute a walkthrough from Sam Ruby's Agile web development.
I've created a directory using mkdir work
Next i'm instructed to open a terminal and type rubys> cd work
The error I'm getting reads:
No command 'rubys' found, did you mean:
Command 'ruby' from package 'ruby' (main)
rubys: command not found
Can anyone inform me of what I'm doing wrong?
I've also tried changing from ~ to the work directory before entering my command.

In this book, rubys> is a command prompt, much like you have C:\> in the Windows terminal.
Ignore that first bit and everything should start working.

I guess you're doing it wrong.
mkdir work
creates a directory called "work". It has nothing to do with Ruby.
cd work
will then change into that directory. Forget about the rubys>.

Related

Ghostscript installed but not found RGhost::Config::GS[:path]='/path/to/my/gs'

I've been trying for a few hours now solve this problem and I looked everywhere for a solution and I did not find one. I'm trying to run a spec test for my project and I have the following error coming up:
RuntimeError:
Ghostscript not found in your system environment (linux-gnu).
Install it and set the variable RGhost::Config::GS[:path] with the executable.
Example: RGhost::Config::GS[:path]='/path/to/my/gs' #unix-style
RGhost::Config::GS[:path]="C:\\gs\\bin\\gswin32c.exe" #windows-style
And I do try to put RGhost::Config::GS[:path]='/usr/local/bin/gs' and it returns:
bash: RGhost::Config::GS[:path]=/usr/local/bin/gs: No such file or directory
but ghostscript is installed, I did everything (make, sudo make install, etc etc) and when I run gs -v it returns:
GPL Ghostscript 9.26 (2018-11-20)
Copyright (C) 2018 Artifex Software, Inc. All rights reserved.
When I use the user interface and search for "gs" in the "Files" application, it is found in /home/marcelle/projects/ghostscript-9.26/bin/gs and I also tried:
RGhost::Config::GS[:path]='/home/marcelle/projects/ghostscript-9.26/bin/gs'
and it returns the same error:
bash: RGhost::Config::GS[:path]=/home/marcelle/projects/ghostscript-9.26/bin/gs: No such file or directory
I also tried to delete ghostscript from my notebook with autoremove and purge and installed it again using what I mentioned before (./configure, make, sudo make install), restarted the notebook, the terminal and nothing.
PS: I'm using Ubuntu 20.04.
I managed to figure out a solution. Looking for the code for the Rghost, what I saw in its spec is that the path expected was different than the path the ghostscript really is.
When I run whereis or which on my terminal, it returns:
which gs
/usr/local/bin/gs
So I was trying to point to this path. But seeing the spec test for Rghost which I found on github for Rghost, we can see that it expects /usr/bin/gs:
it 'should detect linux env properly' do
RbConfig::CONFIG.should_receive(:[]).twice.with('host_os').and_return('linux')
File.should_receive(:exists?).with('/usr/bin/gs').and_return(true)
RGhost::Config.config_platform
RGhost::Config::GS[:path].should == '/usr/bin/gs'
end
So it expects /usr/bin and not /usr/local/bin.
Then I just copied to that path and the spec ran with no problems anymore:
sudo cp /usr/local/bin/gs /usr/bin
I've no experience with Ruby at all, but I also got this error when using asciidoctor, which uses rghost for the PDF generation.
The command RGhost::Config::GS[:path]='/path/to/my/gs' mentioned in the error is not a shell command, which is why bash couldn't handle it. However, to me it wasn't immediately clear what to do with this command either. I expected an easy way to set this variable somewhere, but couldn't find it.
What worked for me was searching the rghost.rb file, which is where this variable is set and can be changed. In Windows, it was located in C:\Ruby30-x64\lib\ruby\gems\3.0.0\gems\rghost-0.9.7\lib\rghost.rb.
In this file, I added the following line, which solved the problem:
RGhost::Config::GS[:path]="C:\\Program Files\\gs\\gs9.55.0\\bin\\gswin64c.exe"
NB: the mentioned paths can be different for everyone, so make sure to use that paths that are valid for your system.

New to Command Prompt - Do I need to prefix every command with "Jruby -S ..."

I'm new to using Window's Command Prompt, and also to developing with Ruby on Rails. Possibly a silly question but one that I'm sure everyone who learns with CodeCademy will end up asking; right now I'm prefixing every command for my project with 'Jruby -S ...", for example:
C:\users\MyName\MyProject> Jruby -S rails new MyApp
...
C:\users\MyName\MyProject> Jruby -S bundle install
...
C:\users\MyName\MyProject> Jruby -S rake db:migrate
Can I use some kind of alternative shell to save me typing Jruby -S every time? I'm aware of bash and powershell but have basically zero knowledge of whether I should be using them...
Thanks folks!
EDIT
Lots of helpful suggestions below, but I was really looking for a shell to mimic the functionality of the console on codecademy.com (which I believe is supposed to work like a Mac's 'bash' program?). Thanks anyway.
I'm new to using Window's Command Prompt
The CMD works very similarly to the GUI/Shell -- you have to call applications and then run commands with them.
The difference between CMD and windows is that CMD is "naked" - you have to ensure all the paths are correct, and that you're calling the correct application each time.
For example, calling rails server literally translates as:
Program = ruby.exe / rails
Command = server
CMD uses the PATH environment variable to make this process smoother.
The PATH var basically allows you to reference applications on your computer from the CLI (command line interface). This means that if you have an application (EG ruby.exe), you can add the ruby.exe directory to your PATH variable, allowing you to call ruby ... straight from cmd.
--
In your case, I don't have much experience with JRuby; I do know, however, that if you want to invoke the functionality of that application, you have to call it from the cli.
Hopefully my answer gives some context.
You can do that with powershell.
I'm sure that there should be a better way to do that, but you can try this
$ruby = "Jruby"
$s = "-S"
& $ruby $s rails new MyApp
I don't work on windows, however the jruby zip files on the download site have a bin directory with .bat and .exe files for jruby, rake, and gem. You could just add the directory you installed jruby to and the 'bin' subdirectory to your PATH to start.
set JRUBY_HOME= your_installed_jruby
set PATH= %PATH%;%JRUBY_HOME%\bin
http://jruby.org/download
I don't know what the windows installer does, but I would think it would do something similar.

How to change back to the first_app directory?

I'm new to Ruby and am trying to make my way through the Hartl tutorial. I ran into a couple issues this morning and am afraid that I might have made one of them worse.
I was doing fine in the tutorial until I got to the Heroku deployment section of chapter 1 and realized that I had yet to setup the Sublime Text 2 "subl" command so that my terminal could interact with Sublime Text.
I then went on a chase to figure out how to get the subl command to work. While trying to get that figured out, I came across this thread (Installing Sublime Text's command line tool 'subl' in terminal, permission denied?) and went ahead and changed directories to the "mkdir bin" so that I could run "sudo ln -s "/Applications/Sublime Text 2.app/Contents/SharedSupport/bin/subl" /usr/bin/subl" and get my subl command line to work.
Well, when I entered the "sudo ln -s...." line it asked for a password and basically said I should be careful what I was doing. In light of that, I just want to return to my "first_app" directory and try to figure stuff out a different way. Only problem is, when I hit "cd first_app" it tells me there is no such file or directory... I'm starting to freak out a little bit now...
How can I get back to the first_app directory? Surely it's not gone?!' <-- most important!!
If I can get back to the first_app directory, how in the world can I get the subl command line so that I can continue on with deployment, etc...?
Any and all help is much appreciated as I try and work through this really frustrating phase.
UPDATE: I just changed it back to the first_app directory -- what is the best way to get this subl command line working?
Depending on what directory you're in, if you try to cd first_app, it may not be a sub-directory of the dir you're currently in.
Some basic linux commands to help you out:
cd .. <-- Moves up a level
pwd <-- Shows where you currently are in the directory structure
ls <-- Shows files/folders that exist in the directory you are in.

System Call in Rails returns 'No such file or directory'

I try to execute shell commands in rails using the following:
result = `which wkhtmltoimage-proxy`
but I always get back:
No such file or directory - which wkhtmltoimage-proxy
If I just type the command in my shell, everything works but not in the rails environment.
Doesn't matter which commands I try, none of the work.
Do I need to configure anything in rails?
I figured it out. I am using an IDE tool and didn't set the environment variables correctly. Anyways, the problem is solved now. Thanks for all your help!
Think of the system ticks (`) as executing in your rails directory (i.e. 'myapp')
So, if you're expecting to run this command in another directory, such as your home folder, you'll have to specify that
result = `cd ~ && which wkhtmltoimage-proxy`
If this is on Windows
This is spec. Ruby doesn't execute any child process in such case on
Windows, so, ruby cannot set any status to $?.
bugs.ruby-lang.org/issues/1690

Having trouble running "mate .rspec"

I'm trying to run mate .rspec in my command prompt in order to open the .rspec configuration file. However, I get the error -bash: mate: command not found. Any ideas?
Though Brandon's answer is correct, there's a far simpler way to set up the mate command through TextMate itself.
In the menu bar, select Help > Terminal Usage..., choose /usr/bin from the dropdown, and it will create the link for you.
You might have to open a new Terminal window for it to take effect, but then you should be all set.
[Update]
T.J.'s answer is much better than mine. :)
[Original Answer]
TextMate installs the mate command to /usr/local/bin/mate. First, I would check to see if the mate command is in that directory:
ls -lah /usr/local/bin/mate
If you get ls: /usr/local/bin/mate: No such file or directory, then you can install the mate command by creating a symbolic link to the binary, which lives in the TextMate.app folder:
sudo ln -s /Applications/TextMate.app/Contents/Resources/mate /usr/local/bin/mate
At this point, you should be able to run mate from the command line.
If you got output other than No such file or directory from the ls command, it means that /usr/local/bin is not on your path.

Resources