Remember to maintain security and privacy. Do not share sensitive information. Procedimento.com.br may make mistakes. Verify important information. Termo de Responsabilidade
Ruby is a dynamic, open-source programming language with a focus on simplicity and productivity. It has an elegant syntax that is natural to read and easy to write. Ruby is widely used for web development, particularly with the Ruby on Rails framework. This article will guide you through the process of installing and running Ruby on macOS, ensuring you can leverage its powerful capabilities on your Apple system.
Examples:
Installing Ruby via Homebrew:
Homebrew is a popular package manager for macOS that simplifies the installation of software.
First, ensure Homebrew is installed. Open Terminal and run:
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
Once Homebrew is installed, you can install Ruby by running:
brew install ruby
Verify the installation by checking the Ruby version:
ruby -v
Running a Simple Ruby Script:
Create a new Ruby file. For example, create a file named hello.rb
:
touch hello.rb
Open hello.rb
in a text editor and add the following code:
puts "Hello, World!"
Save the file and run it via Terminal:
ruby hello.rb
You should see the output:
Hello, World!
Using IRB (Interactive Ruby Shell):
IRB is a REPL (Read-Eval-Print Loop) tool for Ruby, allowing you to execute Ruby commands interactively.
Start IRB by typing:
irb
You can now type Ruby commands directly. For example:
puts "Hello from IRB!"
To exit IRB, simply type:
exit
Installing Ruby on Rails:
Ruby on Rails is a powerful web application framework written in Ruby.
First, install the Rails gem:
gem install rails
Verify the installation by checking the Rails version:
rails -v
Create a new Rails application:
rails new myapp
Navigate to the application directory and start the Rails server:
cd myapp
rails server
Open a web browser and go to http://localhost:3000
to see your new Rails application running.