CentOS 7 配置Ruby语言开发环境

安装Ruby 2.2

CentOS7存储库中的Ruby版本为2.0,但如果需要,可以使用RPM软件包安装2.2

  • 添加CentOS SCLo软件集合存储库
[root@linuxprobe ~]# yum -y install centos-release-scl-rh centos-release-scl
# set [priority=10]
[root@linuxprobe ~]# sed -i -e "s/\]$/\]\npriority=10/g" /etc/yum.repos.d/CentOS-SCLo-scl.repo
[root@linuxprobe ~]# sed -i -e "s/\]$/\]\npriority=10/g" /etc/yum.repos.d/CentOS-SCLo-scl-rh.repo
# for another way,change to [enabled=0] and use it only when needed
[root@linuxprobe ~]# sed -i -e "s/enabled=1/enabled=0/g" /etc/yum.repos.d/CentOS-SCLo-scl.repo
[root@linuxprobe ~]# sed -i -e "s/enabled=1/enabled=0/g" /etc/yum.repos.d/CentOS-SCLo-scl-rh.repo
# if [enabled=0],input a command to use the repository
[root@linuxprobe ~]# yum --enablerepo=centos-sclo-rh install [Package]
[root@linuxprobe ~]# yum --enablerepo=centos-sclo-sclo install [Package]
# 安装ruby
yum --enablerepo=centos-sclo-rh -y install rh-ruby22
  • 软件集合的软件包安装在/opt目录下, 要使用它,需要加载环境变量,如下所示:
# 加载环境变量
[root@linuxprobe ~]# scl enable rh-ruby22 bash
[root@linuxprobe ~]# ruby -v
ruby 2.2.2p95 (2015-04-13 revision 50295) [x86_64-linux]
[root@linuxprobe ~]# which ruby
/opt/rh/rh-ruby22/root/usr/bin/ruby
  • 设置登录时自动启用Ruby 2.2,按如下所示进行配置:
[root@linuxprobe ~]# vim /etc/profile.d/rh-ruby22.sh
#!/bin/bash
source /opt/rh/rh-ruby22/enable
export X_SCLS="`scl enable rh-ruby22 'echo $X_SCLS'`"
export PATH=$PATH:/opt/rh/rh-ruby22/root/usr/local/bin

安装Ruby 2.3

# 安装ruby
yum --enablerepo=centos-sclo-rh -y install rh-ruby23
  • 软件集合的软件包安装在/opt目录下, 要使用它,需要加载环境变量,如下所示:
# 加载环境变量
[root@linuxprobe ~]# scl enable rh-ruby23 bash
[root@linuxprobe ~]# ruby -v
ruby 2.2.2p95 (2015-04-13 revision 50295) [x86_64-linux]
[root@linuxprobe ~]# which ruby
/opt/rh/rh-ruby22/root/usr/bin/ruby
  • 设置登录时自动启用Ruby 2.3,按如下所示进行配置:
[root@linuxprobe ~]# vim /etc/profile.d/rh-ruby23.sh
#!/bin/bash
source /opt/rh/rh-ruby23/enable
export X_SCLS="`scl enable rh-ruby23 'echo $X_SCLS'`"
export PATH=$PATH:/opt/rh/rh-ruby23/root/usr/local/bin

安装Ruby on Rails 4来构建Ruby Framework环境

  • 添加EPEL软件存储库
[root@linuxprobe ~]# yum -y install epel-release
# set [priority=5]
[root@linuxprobe ~]# sed -i -e "s/\]$/\]\npriority=5/g" /etc/yum.repos.d/epel.repo
# for another way,change to [enabled=0] and use it only when needed
[root@linuxprobe ~]# sed -i -e "s/enabled=1/enabled=0/g" /etc/yum.repos.d/epel.repo
# if [enabled=0],input a command to use the repository
[root@linuxprobe ~]# yum --enablerepo=epel install [Package]

Ruby on Rails 4

  • 安装Ruby 2.2,参考上面
  • 安装依赖包(epel+SCLo)
[root@linuxprobe ~]# yum --enablerepo=epel,centos-sclo-rh -y install rh-ruby22-ruby-devel nodejs libuv gcc make libxml2 libxml2-devel mariadb-devel zlib-devel libxslt-devel
  • 安装Rails 4
[root@linuxprobe ~]# gem install bundler
[root@linuxprobe ~]# gem install nokogiri -- --use-system-libraries
[root@linuxprobe ~]# gem install rails --version="~>4.0" --no-ri --no-rdoc
[root@linuxprobe ~]# /opt/rh/rh-ruby22/root/usr/local/bin/rails -v
Rails 4.2.8

Ruby on Rails 5

  • 安装Ruby 2.3,参考上面
  • 安装依赖包(epel+SCLo)
[root@linuxprobe ~]# yum --enablerepo=epel,centos-sclo-rh -y install rh-ruby23-ruby-devel nodejs libuv gcc make libxml2 libxml2-devel mariadb-devel zlib-devel libxslt-devel
  • 安装Rails 5
[root@linuxprobe ~]# gem install bundler
[root@linuxprobe ~]# gem install nokogiri -- --use-system-libraries
[root@linuxprobe ~]# gem install rails --no-ri --no-rdoc
[root@linuxprobe ~]# rails -v
Rails 5.0.2

创建一个示例应用程序,并确保其正常工作

  • 需要安装MariaDB服务
[root@linuxprobe ~]# yum -y install mariadb-server
[root@linuxprobe ~]# vi /etc/my.cnf
# add follows within [MysqLd] section
[MysqLd]
character-set-server=utf8
[root@linuxprobe ~]# systemctl start mariadb
[root@linuxprobe ~]# systemctl enable mariadb
ln -s '/usr/lib/systemd/system/mariadb.service' '/etc/systemd/system/multi-user.target.wants/mariadb.service'
  • 初始化MariaDB
[root@linuxprobe ~]# MysqL_secure_installation

NOTE: RUNNING ALL PARTS OF THIS SCRIPT IS RECOMMENDED FOR ALL MariaDB
      SERVERS IN PRODUCTION USE!  PLEASE READ EACH STEP CAREFULLY!

In order to log into MariaDB to secure it,we'll need the current
password for the root user.  If you've just installed MariaDB,and
you haven't set the root password yet,the password will be blank,so you should just press enter here.

Enter current password for root (enter for none):
OK,successfully used password,moving on...

Setting the root password ensures that nobody can log into the MariaDB
root user without the proper authorisation.

# set root password
Set root password? [Y/n] y
New password:
Re-enter new password:
Password updated successfully!
Reloading privilege tables..
 ... Success!

By default,a MariaDB installation has an anonymous user,allowing anyone
to log into MariaDB without having to have a user account created for
them.  This is intended only for testing,and to make the installation
go a bit smoother.  You should remove them before moving into a
production environment.
# remove anonymous users
Remove anonymous users? [Y/n] y
 ... Success!

normally,root should only be allowed to connect from 'localhost'.  This
ensures that someone cannot guess at the root password from the network.

# disallow root login remotely
disallow root login remotely? [Y/n] y
 ... Success!

By default,MariaDB comes with a database named 'test' that anyone can
access.  This is also intended only for testing,and should be removed
before moving into a production environment.

# remove test database
Remove test database and access to it? [Y/n] y
 - Dropping test database...
 ... Success!
 - Removing privileges on test database...
 ... Success!

Reloading the privilege tables will ensure that all changes made so far
will take effect immediately.

# reload privilege tables
Reload privilege tables Now? [Y/n] y
 ... Success!

Cleaning up...

All done!  If you've completed all of the above steps,your MariaDB
installation should Now be secure.

Thanks for using MariaDB!

# connect to MariaDB with root
[root@linuxprobe ~]# MysqL -u root -p
Enter password:
Welcome to the MariaDB monitor.  Commands end with ; or \g.
Your MariaDB connection id is 11
Server version: 5.5.52-MariaDB MariaDB Server

copyright (c) 2000,2016,Oracle,MariaDB Corporation Ab and others.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

# show user list
MariaDB [(none)]> select user,host,password from MysqL.user;
+------+-----------+-------------------------------------------+
| user | host      | password                                  |
+------+-----------+-------------------------------------------+
| root | localhost | *E2ACEC2F2DA384EE6753673365DFEF35F0C272C9 |
| root | 127.0.0.1 | *E2ACEC2F2DA384EE6753673365DFEF35F0C272C9 |
| root | ::1       | *E2ACEC2F2DA384EE6753673365DFEF35F0C272C9 |
+------+-----------+-------------------------------------------+
3 rows in set (0.00 sec)

# show database list
MariaDB [(none)]> show databases;
+--------------------+
| Database           |
+--------------------+
| information_schema |
| MysqL              |
| performance_schema |
+--------------------+
3 rows in set (0.00 sec)

MariaDB [(none)]> exit
Bye
  • 创建测试应用程序
[root@linuxprobe ~]# gem install MysqL2 --no-ri --no-rdoc -- --with-MysqL-config=/usr/bin/MysqL_config
[root@linuxprobe ~]# rails new SampleApp -d MysqL
[root@linuxprobe ~]# cd SampleApp
[root@linuxprobe SampleApp]# vi config/database.yml
default: &default
  adapter: MysqL2
  encoding: utf8
  pool: 5
  username: root
  password: password   # MariaDB password
  socket: /var/lib/MysqL/MysqL.sock
# create test application
[root@dlp SampleApp]# rails db:create
Created database 'SampleApp_development'
Created database 'SampleApp_test'
[root@dlp SampleApp]# rails generate scaffold testapp name:string title:string body:text
[root@dlp SampleApp]# rails db:migrate
[root@dlp SampleApp]# rails server --binding=0.0.0.0 => Booting Puma => Rails 5.0.2 application starting in development on http://0.0.0.0:3000 => Run `rails server -h` for more startup options
Puma starting in single mode...
* Version 3.8.2 (ruby 2.3.1-p112),codename: Sassy Salamander
* Min threads: 5,max threads: 5
* Environment: development
* Listening on tcp://0.0.0.0:3000
Use Ctrl-C to stop
  • 客户端访问http://10.1.1.53:3000/

CentOS 7 配置Ruby语言开发环境的更多相关文章

  1. ios – ipatool无法使用bitcode构建(xcode 7.1.1)

    在日志中我发现的是:有小费吗?解决方法在管理器上单击“分发应用程序”后,我在XCode10.1上遇到了同样的问题.在我的情况下,这是因为我从我的终端调用XCode并且rvm配置了不同的ruby版本.运行rvm系统为我修复了它.

  2. XCode 3.2 Ruby和Python模板

    在xcode3.2下,我的ObjectiveCPython/Ruby项目仍然可以打开更新和编译,但是你无法创建新项目.鉴于xcode3.2中缺少ruby和python的所有痕迹(即创建项目并添加新的ruby/python文件),是否有一种简单的方法可以再次安装模板?我发现了一些关于将它们复制到某个文件夹的信息,但我似乎无法让它工作,我怀疑文件夹的位置已经改变为3.2.解决方法3.2中的应用程序模板

  3. macos – 运行brew命令充满了’同意Xcode / iOS许可证需要管理员权限,请通过sudo以root身份重新运行.’

    所以我跑了:如果滚动到底部,可以输入“同意”,然后就可以了.

  4. ios – 为具有多个目标和不同平台的项目编写Podfile

    如何让CocoaPods成功整合到我的项目和iOS/Mac目标?我已经阅读了Podfile文档,但发现它在这方面缺乏.解决方法得到它了!从我的每个目标和运行的pod安装中删除libPods-xxxx.a文件,再次执行了我的目标集成.

  5. ios – 从Xcode Cocapods插件运行pod安装

    我正在尝试从Xcodecocoapodsplugin运行pod安装命令.当我运行update/installcocoapods命令我得到一个错误:这是奇怪的,如果我去终端中的目录,并运行一个pod安装我没有问题.要注意的是,错误是指Ruby2.0.0,而当我从终端中的目录运行ruby-v命令时,我得到(ruby1.9.3p327(2012-11-10修订版37606)[x86_64-darwin1

  6. ios – 仅适用于iPad的Settings.bundle?

    我有一种情况需要通过设置应用程序为我的应用程序提供一个设置.我的应用程序是通用的,但这个特殊的设置只在iPad上有意义,所以我只希望我的应用程序显示在iPad上的设置中.这可能吗?

  7. ios – Swift 4设置捆绑,获取默认值

    我创建了一个包含大约8个切换开关的设置包.我想要做的是从设置包中获取默认值.目前我现在有这两种方法:我在viewDidLoad中调用这些方法然而,这并没有得到我的默认值.如果我关闭应用程序,打开设置,调整设置并重新打开应用程序,这会产生正确的值.有没有获得默认设置?

  8. Swift调用OC和C

    Swift文件:main.swiftOC文件:Root.hRoot.mC函数文件:Fun.c桥接文件:工程名称-Bridging-Header.h

  9. OC调用Swift

    修改main.m文件OC文件:Root.hRoot.mSwift文件:Person.swift

  10. Swift中实现ruby中字符串乘法倍增的功能

    hopy;)我们知道在ruby中对于字符串类型我们可以用乘法生成一个指定数量重复的字符串:但在Swift中String默认是没有该实现的,不过要想实现该方法也十分之简单,只要定义一个*法操作符就可以了:

随机推荐

  1. 在airgapped(离线)CentOS 6系统上安装yum软件包

    我有一个CentOS6系统,出于安全考虑,它已经被空气泄漏.它可能从未连接到互联网,如果有,它很长时间没有更新.我想将所有.rpm软件包放在一个驱动器上,这样它们就可以脱机安装而无需查询互联网.但是,我在测试VM上遇到的问题是,即使指定了本地路径,yum仍然会挂起并尝试从在线存储库进行更新.另外,有没有办法使用yum-utils/yumdownloader轻松获取该包的所有依赖项和所有依赖项?目前

  2. centos – 命名在日志旋转后停止记录到rsyslog

    CentOS6.2,绑定9.7.3,rsyslog4.6.2我最近设置了一个服务器,我注意到在日志轮换后,named已停止记录到/var/log/messages.我认为这很奇怪,因为所有日志记录都是通过rsyslog进行的,并且named不会直接写入日志文件.这更奇怪,因为我在更新区域文件后命名了HUPed,但它仍然没有记录.在我停止并重新启动命名后,记录恢复.这里发生了什么?

  3. centos – 显示错误的磁盘大小

    对于其中一个磁盘,Df-h在我的服务器上显示错误的空白区域:Cpanel表明它只有34GB免费,但还有更多.几分钟前,我删除了超过80GB的日志文件.所以,我确信它完全错了.fdisk-l/dev/sda2也显示错误:如果没有格式化,我该怎么做才能解决这个问题?并且打开文件描述符就是它需要使用才能做到这一点.所以…使用“lsof”并查找已删除的文件.重新启动写入日志文件的服务,你很可能会看到空间可用.

  4. 如何在centos 6.9上安装docker-ce 17?

    我目前正在尝试在centOS6.9服务器上安装docker-ce17,但是,当运行yuminstalldocker-ce时,我收到以下错误:如果我用跳过的标志运行它我仍然得到相同的消息,有没有人知道这方面的方法?

  5. centos – 闲置工作站的异常负载平均值

    我有一个新的工作站,具有不寻常的高负载平均值.机器规格是:>至强cpu>256GB的RAM>4x512GBSSD连接到LSI2108RAID控制器我从livecd安装了CentOS6.564位,配置了分区,网络,用户/组,并安装了一些软件,如开发工具和MATLAB.在启动几分钟后,工作站负载平均值的值介于0.5到0.9之间.但它没有做任何事情.因此我无法理解为什么负载平均值如此之高.你能帮我诊断一下这个问题吗?

  6. centos – Cryptsetup luks – 检查内核是否支持aes-xts-plain64密码

    我在CentOS5上使用cryptsetupluks加密加密了一堆硬盘.一切都很好,直到我将系统升级到CentOS6.现在我再也无法安装磁盘了.使用我的关键短语装载:我收到此错误:在/var/log/messages中:有关如何装载的任何想法?找到解决方案问题是驱动器使用大约512个字符长的交互式关键短语加密.出于某种原因,CentOS6中的新内核模块在由旧版本创建时无法正确读取512个字符的加密密钥.似乎只会影响内核或cryptsetup的不同版本,因为在同一系统上创建和打开时,512字符的密钥将起作用

  7. centos – 大量ssh登录尝试

    22个我今天登录CentOS盒找到以下内容这是过去3天内的11次登录尝试.WTF?请注意,这是我从我的提供商处获得的全新IP,该盒子是全新的.我还没有发布任何关于此框的内容.为什么我会进行如此大量的登录尝试?是某种IP/端口扫描?基本上有4名匪徒,其中2名来自中国,1名来自香港,1名来自Verizon.这只发生在SSH上.HTTP上没有问题.我应该将罪魁祸首子网路由吗?你们有什么建议?

  8. centos – kswap使用100%的CPU,即使有100GB的RAM也可用

    >Linux内核是否应该足够智能,只需从内存中清除旧缓存页而不是启动kswap?

  9. centos – Azure将VM从A2 / 3调整为DS2 v2

    我正在尝试调整前一段时间创建的几个AzureVM,从基本的A3和标准A3到标准的DS2v2.我似乎没有能力调整到这个大小的VM.必须从头开始重建服务器会有点痛苦.如果它有所不同我在VM中运行CentOS,每个都有一个带有应用程序和操作系统的磁盘.任何人都可以告诉我是否可以在不删除磁盘的情况下删除VM,创建新VM然后将磁盘附加到新VM?

  10. centos – 广泛使用RAM时服务器计算速度减慢

    我在非常具体的情况下遇到服务器速度下降的问题.事实是:>1)我使用计算应用WRF>2)我使用双XeonE5-2620v3和128GBRAM(NUMA架构–可能与问题有关!

返回
顶部