Home>

Ruby environment construction (Windows)

Error message

Installed ruby ​​2.4.9 using RubyInstaller2 with MSYS2 installer.
I checked the installation of Ruby by entering ruby ​​-v at the command prompt.
Using Atom, I created a directory called index.rb in a folder called ruby_lesson.
Even if cd Desktop and cd ruby_lesson are executed at the command prompt, the following error code 1 is displayed.
Furthermore, even if ruby ​​index.rb is executed, the command in the directory is not executed and the following error code 2 is displayed.

Error code 1: The specified path cannot be found
Error code 2: ruby: No such file or directory-index.rb (LoadError)
Applicable source code
Ruby
  • Answer # 1

    cd Desktopmeans "Move the current directory to a directory called Desktop in the current directory".
    An error occurs if there is no Desktop directory in the current directory.

    Similarly,ruby ​​index.rbmeans "execute a file called index.rb in the current directory with ruby", so it is called index.rb in the current directory. If there is no file, an error occurs.

    If you are working with files and directories that should be in the current directory, if you are a beginner, you should make sure they are in the current directory. You can check with thedircommand. If it is not displayed with thedircommand, it will not be there (although it may be a hidden file on Windows).

    I think that there is a file calledindex.rbin a folder calledruby_lesson
    In Explorer, with the folderruby_lessonopen, entercmdin the part surrounded by the red frame below to open the command prompt with that as the current directory So, after confirming thatindex.rbexists indir, enterruby ​​index.rb.