ruby与ruby on rails环境部署

环境:centos7 Mini安装

下载软件包

Ruby
    官网:http://www.ruby-lang.org/en/downloads/
    具体地址:https://cache.ruby-lang.org/pub/ruby/2.7/ruby-2.7.0.tar.gz
RubyGems
    官网:https://rubygems.org/pages/download
    具体地址:https://rubygems.org/rubygems/rubygems-3.1.2.tgz
Sqlite3
    官网:https://www.sqlite.org/download.html
    具体地址:https://www.sqlite.org/2020/sqlite-autoconf-3310100.tar.gz
Openssl
    官网:https://www.openssl.org/source/
    具体地址:https://www.openssl.org/source/openssl-1.1.1d.tar.gz

# cd /software
# wget https://cache.ruby-lang.org/pub/ruby/2.7/ruby-2.7.0.tar.gz
# wget https://rubygems.org/rubygems/rubygems-3.1.2.tgz
# wget https://www.sqlite.org/2020/sqlite-autoconf-3310100.tar.gz
# wget https://www.openssl.org/source/openssl-1.1.1d.tar.gz

0.安装nodejs

# curl --silent --location https://rpm.nodesource.com/setup_10.x | sudo bash
# yum -y install nodejs
# node -v

1.安装Openssl

# cd /software
# tar xvf openssl-1.1.1d.tar.gz
# cd openssl-1.1.1d

# ./config -fPIC --prefix=/usr/local/openssl enable-shared
# ./config -t

# make && make install

2.安装Sqlite3

# cd /software/
# tar xvzf sqlite-autoconf-3310100.tar.gz 
# cd sqlite-autoconf-3310100
# ./configure --prefix=/usr/local
# make && make install

3.安装Ruby

# cd /software
# tar xvf ruby-2.7.0.tar.gz
# cd ruby-2.7.0
# ./configure
# make 
# make install

[
若
/software/ruby-2.7.0/lib/rubygems/core_ext/kernel_require.rb:92:in `require': cannot load such file -- openssl (LoadError)
则

# cd /software/ruby-2.7.0/ext/openssl
# ruby extconf.rb --with-openssl-include=/usr/local/openssl/include/ --with-openssl-lib=/usr/local/openssl/lib
# make 
# make install
再回到上面
# cd /software/ruby-2.7.0
# make install
]



# ruby -v
ruby 2.7.0p0 (2019-12-25 revision 647ee6f091) [x86_64-linux]

4.安装RubyGems

# cd /software
# tar zxvf rubygems-3.1.2.tgz
# cd rubygems-3.1.2
# ruby setup.rb

[
若
/software/rubygems-3.1.2/lib/rubygems/core_ext/kernel_require.rb:92:in `require': cannot load such file -- zlib (LoadError)
则
# yum -y install zlib-devel
然后
# cd /software/ruby-2.7.0/ext/zlib/
# ruby extconf.rb
# make
# make install
再回到上面
# cd /software/rubygems-3.1.2
# ruby setup.rb
]


# gem -v
3.1.2

5.安装Rails

查看gem源
# gem source -l

删除所有的gem源
# gem source -r 上面查到的Url

添加一个gem源
# gem source -a http://gems.ruby-china.com/

刷新source的cache
# gem source -u

# gem install rails
# rails -v

6.新建一个项目

先准备一个项目目录,自己解决

# rails new ./hello

提示黄字Don't run Bundler as root.....等等时
Ctrl+C手动终止,其实hello已经建立
# cd hello
# vi Gemfile
把第一行的source源url换成
http://gems.ruby-china.com/
保存,再执行
# bundle
# curl --silent --location https://dl.yarnpkg.com/rpm/yarn.repo | sudo tee /etc/yum.repos.d/yarn.repo
# yum install -y yarn
# rails webpacker:install

# rails s
若如下
=> Booting Puma
=> Rails 6.0.2.1 application starting in development 
=> Run `rails server --help` for more startup options
/usr/local/lib/ruby/gems/2.7.0/gems/actionpack-6.0.2.1/lib/action_dispatch/middleware/stack.rb:37: warning: Using the last argument as keyword parameters is deprecated; maybe ** should be added to the call
/usr/local/lib/ruby/gems/2.7.0/gems/actionpack-6.0.2.1/lib/action_dispatch/middleware/static.rb:110: warning: The called method `initialize' is defined here
Puma starting in single mode...
* Version 4.3.1 (ruby 2.7.0-p0), codename: Mysterious Traveller
* Min threads: 5, max threads: 5
* Environment: development
* Listening on tcp://127.0.0.1:3000
* Listening on tcp://[::1]:3000
Use Ctrl-C to stop

则成功

6.配置

查看ruby on rails的web服务帮助
rails server -h

Usage:
  rails server -u [thin/puma/webrick] [options]

Options:
  -e, [--environment=ENVIRONMENT]              # Specifies the environment to run this server under (test/development/production).特指一个环境变量文件
  -p, [--port=port]                            # Runs Rails on the specified port - defaults to 3000.特指一个端口号
  -b, [--binding=IP]                           # Binds Rails to the specified IP - defaults to 'localhost' in development and '0.0.0.0' in other environments'.绑定一个特殊的IP
  -c, [--config=file]                          # Uses a custom rackup configuration.
                                               # Default: config.ru 调用一个配置文件与默认
  -d, [--daemon], [--no-daemon]                # Runs server as a Daemon. 后台运行
  -u, [--using=name]                           # Specifies the Rack server used to run the application (thin/puma/webrick).
  -P, [--pid=PID]                              # Specifies the PID file.
                                               # Default: tmp/pids/server.pid
  -C, [--dev-caching], [--no-dev-caching]      # Specifies whether to perform caching in development.
      [--early-hints], [--no-early-hints]      # Enables HTTP/2 early hints.
      [--log-to-stdout], [--no-log-to-stdout]  # Whether to log to stdout. Enabled by default in development when not daemonized.


结论:
# rails server -b 0.0.0.0 -p 3001 -d
指明特定的IP 和端口 后台运行

7.安装mysql

# yum install mysql-devel

# vi Gemfile
gem 'mysql2', '~> 0.3.0'

# bundle

 

  • 1
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 8
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 8
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值