Ruby: erinevus redaktsioonide vahel

Allikas: Imre kasutab arvutit
Mine navigeerimisribaleMine otsikasti
42. rida: 42. rida:
   
 
===Gem rakendus===
 
===Gem rakendus===
  +
  +
Paigaldamine algab Gemfile ettavalmistamisest
  +
  +
<pre>
  +
ruby@ubuntu-2604-01:~/20260605-2$ cat Gemfile
  +
source 'https://rubygems.org'
  +
gem 'sinatra'
  +
</pre>
  +
  +
paigaldamine
  +
  +
<pre>
  +
ruby@ubuntu-2604-01:~/20260605-2$ bundle check
  +
ruby@ubuntu-2604-01:~/20260605-2$ bundle install
  +
</pre>
  +
  +
Paistab, et puuduvad rackup ja puma
  +
  +
<pre>
  +
ruby@ubuntu-2604-01:~/20260605-2$ bundle add rackup puma
  +
Fetching gem metadata from https://rubygems.org/....
  +
Resolving dependencies...
  +
Fetching gem metadata from https://rubygems.org/....
  +
Fetching nio4r 2.7.5
  +
Fetching puma 8.0.2
  +
Fetching rackup 2.3.1
  +
Installing rackup 2.3.1
  +
Installing nio4r 2.7.5 with native extensions
  +
Installing puma 8.0.2 with native extensions
  +
</pre>
  +
  +
kusjuures tulemusena on Gemfile sisus kaks rida juures
  +
  +
<pre>
  +
ruby@ubuntu-2604-01:~/20260605-2$ cat Gemfile
  +
source 'https://rubygems.org'
  +
gem 'sinatra'
  +
gem "rackup", "~> 2.3"
  +
gem "puma", "~> 8.0"
  +
</pre>
  +
  +
serveri ettevalmistamine
   
 
<pre>
 
<pre>

Redaktsioon: 6. juuni 2026, kell 21:19

Sissejuhatus

Misc

ruby@ubuntu-2604-01:~$ curl -fsSL https://github.com/rbenv/rbenv-installer/raw/HEAD/bin/rbenv-installer | bash

ruby@ubuntu-2604-01:~$ rbenv install -l

ruby@ubuntu-2604-01:~$ rbenv install 3.3.0
==> Downloading ruby-3.3.0.tar.gz...
-> curl -q -fL -o ruby-3.3.0.tar.gz https://cache.ruby-lang.org/pub/ruby/3.3/ruby-3.3.0.tar.gz
  % Total    % Received % Xferd  Average Speed  Time    Time    Time   Current
                                 Dload  Upload  Total   Spent   Left   Speed
100 21.04M 100 21.04M   0      0 11.16M      0   00:01   00:01         11.16M
==> Installing ruby-3.3.0...
-> ./configure "--prefix=$HOME/.rbenv/versions/3.3.0" --enable-shared --with-ext=openssl,psych,+
-> make -j 4
-> make install
==> Installed ruby-3.3.0 to /home/ruby/.rbenv/versions/3.3.0

NOTE: to activate this Ruby version as the new default, run: rbenv global 3.3.0

ruby@ubuntu-2604-01:~$ rbenv global 3.3.0
ruby@ubuntu-2604-01:~$ find . -mmin -1 -ls
   393269      4 drwxrwxr-x  15 ruby     ruby         4096 Jun  6 15:28 ./.rbenv
   413953      4 -rw-rw-r--   1 ruby     ruby            6 Jun  6 15:28 ./.rbenv/version
ruby@ubuntu-2604-01:~$ cat ./.rbenv/version
3.3.0

ruby@ubuntu-2604-01:~$ ruby -v
ruby 3.3.0 (2023-12-25 revision 5124f9ac75) [x86_64-linux]

ruby@ubuntu-2604-01:~$ which ruby
/home/ruby/.rbenv/shims/ruby

ruby@ubuntu-2604-01:~$ which gem
/home/ruby/.rbenv/shims/gem

Gem haldus

Gem rakendus

Paigaldamine algab Gemfile ettavalmistamisest

ruby@ubuntu-2604-01:~/20260605-2$ cat Gemfile
source 'https://rubygems.org'
gem 'sinatra'

paigaldamine

ruby@ubuntu-2604-01:~/20260605-2$ bundle check
ruby@ubuntu-2604-01:~/20260605-2$ bundle install

Paistab, et puuduvad rackup ja puma

ruby@ubuntu-2604-01:~/20260605-2$ bundle add rackup puma
Fetching gem metadata from https://rubygems.org/....
Resolving dependencies...
Fetching gem metadata from https://rubygems.org/....
Fetching nio4r 2.7.5
Fetching puma 8.0.2
Fetching rackup 2.3.1
Installing rackup 2.3.1
Installing nio4r 2.7.5 with native extensions
Installing puma 8.0.2 with native extensions

kusjuures tulemusena on Gemfile sisus kaks rida juures

ruby@ubuntu-2604-01:~/20260605-2$ cat Gemfile
source 'https://rubygems.org'
gem 'sinatra'
gem "rackup", "~> 2.3"
gem "puma", "~> 8.0"

serveri ettevalmistamine

ruby@ubuntu-2604-01:~/20260605-2$ cat server.rb
# server.rb
require 'sinatra'

# Tell Sinatra to accept connections from outside your local host loop
set :bind, '0.0.0.0'
set :port, 4567

# Define the visual landing pad for your web browser
get '/' do
  "<h1>Hello World from Ruby!</h1>
   <p>Your isolated rbenv environment is running a live web server seamlessly!</p>"
end

Käivitamine

ruby@ubuntu-2604-01:~/20260605-2$ bundle exec ruby server.rb
== Sinatra (v4.2.1) has taken the stage on 4567 for development with backup from Puma
Puma starting in single mode...
* Puma version: 8.0.2 ("Into the Arena")
* Ruby version: ruby 4.0.5 (2026-05-20 revision 64336ffd0e) +PRISM [x86_64-linux]
*  Min threads: 0
*  Max threads: 5
*  Environment: development
*          PID: 54882
* Listening on http://0.0.0.0:4567
Use Ctrl-C to stop
192.168.10.156 - - [06/Jun/2026:17:18:57 +0000] "GET / HTTP/1.1" 200 114 0.0016
192.168.10.156 - - [06/Jun/2026:17:18:58 +0000] "GET /favicon.ico HTTP/1.1" 404 441 0.0009
192.168.10.156 - - [06/Jun/2026:17:18:58 +0000] "GET / HTTP/1.1" 200 114 0.0006
192.168.10.156 - - [06/Jun/2026:17:18:59 +0000] "GET / HTTP/1.1" 200 114 0.0005
192.168.10.156 - - [06/Jun/2026:17:18:59 +0000] "GET / HTTP/1.1" 200 114 0.0007
192.168.10.156 - - [06/Jun/2026:17:18:59 +0000] "GET / HTTP/1.1" 200 114 0.0008
^C- Gracefully stopping, waiting for requests to finish
=== puma shutdown: 2026-06-06 18:13:59 +0000 ===
- Goodbye!
== Sinatra has ended his set (crowd applauds)
ruby@ubuntu-2604-01:~/20260605-2$

Kasulikud lisamaterjalid

  • TODO