Trying to teach myself Ruby and using the Book Apress Beginning Ruby. I bought TextMate 2 and in the very beginning of Chap. 4 I am being asked for following:
Launch Terminal (Completed)
Use cd to navigate to the folder where you placed example1.rb, like so:cd ~/ruby. This tells Terminal to take you to the ruby folder located off of your home user folder. (Can't figure this out. What is "cd". Where do I type this TextMate 2 or Terminal. Do I type irb prior? I saved the example1.rb on my desktop, tried to drag and drop, says permission denied).
Type ruby example1.rb and press Enter to execute the example1.rb Ruby script.
If you get an error such as ruby:No such file or directory -- example1.rb (LoadError), you aren’t in the same folder as the example1.rb source file, and you need to establish where you have saved it. (Obviously I get this error, but I can't complete step 2).
Was super excited getting through chap 1-3 and using irb and now I bought TextMate2 and I get stuck trying to start my first ruby app.
Can anyone help explain Step 2 so I can complete 3 and 4?
What is "cd"
cd is change directory command. Type it in your terminal like this:
cd /dir/that/has/example1.rb
If example1.rb is in your Desktop and you are using Mac and your username is tom, then cd command would be:
cd /Users/tom/Desktop
Then from the terminal again, type:
ruby example1.rb
to run your Ruby script.
Related
ugh! In the course of working in my perfectly good rails environment, I did something bad:
While running my local sandbox, looking in Chrome developer tools/sources (this is for our own codebase), I clicked an item in the sources list and doing so prompted downloading a file: Roboto-Regular-e60d1ba1cef90e4a4da5c9e2fe1ec3b1.woff2
I got a "threat detected" popup
I submitted the screen I was on, and saw an error to the effect of 'no data', and rails server had stopped
Now I'm having the following symptoms:
Typing "rails server" (or even just "rails") gives me a "No such file or directory" error for /usr/local/Cellar/rbenv/1.1.1/libexec/rbenv.
the following script (with no modifications since its original create date last year) has the line looking for that file : /.rbenv/shims/rails
in the directory in question (libexec), I don't see a plain "rbenv" file, only these with more specific names: rbenv---version, rbenv-help, rbenv-realpath.dylib, rbenv-version, rbenv-version-origin, rbenv-commands, rbenv-hooks, rbenv-root, rbenv-version-file, rbenv-versions, rbenv-completions, rbenv-init, rbenv-sh-rehash, rbenv-version-file-read, rbenv-whence, rbenv-exec, rbenv-local, rbenv-sh-shell, rbenv-version-file-write, rbenv-which rbenv-global, rbenv-prefix, rbenv-shims, rbenv-version-name
I've just used homebrew to upgrade rbenv, but the symptom is still the same.
My $PATH variable has:
-bash: /Users/drkaplan/.rvm/gems/ruby-2.2.2/bin:/Users/drkaplan/.rvm/gems/ruby-2.2.2#global/bin:/Users/drkaplan/.rvm/rubies/ruby-2.2.2/bin:/Users/drkaplan/.rvm/bin:/Users/drkaplan/.nvm/versions/node/v6.11.2/bin:/Users/drkaplan/google-cloud-sdk/bin:/Users/drkaplan/.rbenv/shims:/Users/drkaplan/.local/bin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/MacGPG2/bin:/Applications/Postgres.app/Contents/Versions/latest/bin: No such file or directory
Ideas for where to look next?
The solution in this case was to reinstall rails:
gem install rails
I have a problem with all my three! Ubuntu systems. I can't create any Rails projects anymore with the following command
rails new abcde
I get the following error message.
Can't initialize a new Rails application within the directory of another, please change to a non-Rails directory first
I know the error message is really clear, I googled and checked all the entries here on StackOverflow. No one had another explanation other than there is a project in a parent folder, which is not the case in my systems!
I checked all folders back to root for any hidden files resembling a rails project. Nothing! I even created a new folder under root /projects and tried to create a project in there, same error. I don't know what to do anymore, I have the same problem on all three of my Ubuntu computers. Has anyone ever had this problem and could fix it? What could be another cause of this. Because there is no project in any of parent folders.
The only possible solution for me is, that there is maybe a PATH variable for Rails that I don't know about and there is maybe a project in there?
SUGGESTIONS:
0) I'm assuming you're typing these commands from a console window, and not executing a shell script, shortcut, or "something else". Correct?
1) Please update your post with the following: ruby -v; rails -v (Ruby and Rails version info)
2) Please try another test project, and copy/paste any error or warning messages you see:
cd /tmp
rails new abc -f
<= another test "rails new", with "--force" option
3) Assuming you've installed RVM, and assuming your "rails new" is calling "run bundle install", then also make sure your user is a member of the "rvm" group:
sudo usermod -G rvm -a MYUSER
4) If you haven't already, please also look at these links:
can't initialize a new rails application within the directory of another
Problems with RVM and Rails when creating new app
I am receiving the error No such file or directory in my command line and I think it's because I am not saving the ruby files somewhere specific. All I did was create a random folder where I would save my ruby files.
Do I need to save my scripts in the original ruby folder? Thanks!
** This is Windows 7.
More info -
All I did was make a simple file named "Matz.rb" because I'm currently reading the O'reilly Ruby book. In my code all I wrote was puts "Hello Matz". I saved this on my desktop. When I go to the command line it and I write ruby matz.rb it says "ruby: No such file or directory -- matz.rb " Please help :(
If this has something to do with PATH or shells, I honestly have no idea what those really are because I just started coding last night.
You are most likely not in the right folder. You somehow need to tell the ruby interpreter where it is looking for the file.
Either make sure you're in the right folder - the cd command allows you to change location:
cd C:\Users\Username\Desktop
ruby Matz.rb
or specify the path explicitly:
ruby C:\Users\Username\Desktop\Matz.rb
By default, the ruby interpreter will look in your current directory (the location shown in your prompt) for whatever filename you give it.
Edit: I'll attempt to explain what I mean step-by-step.
When you initially open the command prompt, it will indicate what folder you are in (your "current working directory") in the prompt:
C:\Users\YourUsername >
In the above example, you are working in the C:\Users\YourUsername folder.
You can move directories using the cd command. For example, typing cd Desktop moves you into the folder called Desktop, assuming such a folder exists in your current location
You can move to another folder outside your current folder by specifying explicitly where you want to be: cd C:\Another\Place
When you run a ruby command such as ruby Matz.rb, the system knows how to find the ruby program because the installer placed its location into the PATH environment variable. Don't worry about this too much, this just explains the "magic" by which it knows what ruby means, no matter where you are.
Ruby finds the file you specify (in the above example, Matz.rb) by looking in the current directory. To re-iterate, it is looking in whatever folder is written right there in your prompt.
You can tell ruby to look outside the current folder by specifying the full path (as shown in the answer above).
To go from a new command window that you've just opened, to typing ruby Matz.rb and having it work, you need to do the following:
Move to the correct directory
Run the command
If we assume your username is alex and you have a folder on your desktop called "rubycode", which contains Matz.rb, you could do this:
Open a command prompt, which will most likely start in C:\Users\Alex
Move to the rubycode folder on your desktop: cd Desktop\rubycode. All subsequent commands will be working from within this folder.
Run the ruby command, specifying the file: ruby Matz.rb
Continue to run ruby commands as you learn ruby.
I hope that makes sense.
I'm going through the railstutorial.org Chapter 3 tutorial and the instructor asked us to create a new html file with the command:
$ mate public/hello.html
However, I'm not using Textmate in this case, but rather Smultron as my text editor. That said, I receive the error message:
-bash: mate: command not found
Do you know what word I should replace "mate" with to properly communicate with Smultron?
When Textmate is installed, it puts a mate executable in /usr/local/bin/. If you're not using Textmate, you won't have that command.
Older versions of Smultron placed a smultron executable in the path. I don't imagine that's changed, but I don't have the lastest version of Smultron to confirm that. I also don't remember if you have to provide any kind of command line switches when creating a new file.
Edit: To get command-line support in Smultron 4, download this: http://www.peterborgapps.com/wp-content/uploads/2011/07/smultron-commandlineutility4.zip
I just installed ruby on rails on my new computer ( I was using instantrails before) and I'm trying to get everything setup.
Im running Windows 7. So I followed the instructions from this tutorial.
http://blogupstairs.com/ruby-on-rails/installing-ruby-on-rails-on-windows-7/
The problem i'm guessing is step 3
"Add the newly installed bin directory to your path in your windows system : Open windows explorer-> right click the icon computer-> choose Properties -> in the contol panel Home, Click Advanced system settings and then click Envitonment Variables button->in the system variables click new and add new system variables like this : Variable name : RUBY_HOME , Variable Value : C:\Ruby, after that add it in to the path and add the bin after a semicolon to the “Path” variable like this : C:\Program Files\Common Files\Adobe\AGL;%JAVA_HOME%\bin;%ANDROID_HOME%\tools;%RUBY_HOME%\bin"
I set created the system variables but when I try to run script/generate in the main directory of my app I get the error
"Ruby: no such file or directory --script/generate"
I checked the apps directory and the script folder is in there. How can I run the "ruby script/generate" commands from the control panel?
I was guessing it was something with the path but I dont know any ways to check to find out whats going wrong.
Are you using Rails 3.0+? In this version of rails and up, the script/* folder has been deprecated in favor of rails generate, rails server, etc. See here.
In 99.99999% of all cases, if a computer tells you that it cannot find a file at a specific location, it is because that file is not at that specific location.
So, is there actually a file named generate in a directory named script in the current directory?
I have recently installed RoR on my "clean" Win7 as well.
What IDE are you using?
I suggest trying JRuby with NetBeans/RubyMine:
JRuby installer does all the work (even adds the proper variables to your path in system environment settings...,
IDEs take care of gems, setting up servers etc.
As for the commands, as Nuclearsandwitch mentioned, there is no script/generate or script/server in Rails 3. Just make sure you in the directory with your Rails app and then try running rails server. It should work :-)