CentOS 7下配置Ruby语言开发环境的方法教程

本文跟大家分享的是在CentOS 7下配置Ruby语言开发环境的方法教程,分享出来供大家参考学习,下面来看看详细的介绍:

安装Ruby 2.2

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

1、添加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

2、软件集合的软件包安装在/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

3、设置登录时自动启用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

1、软件集合的软件包安装在/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

2、设置登录时自动启用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环境

1、添加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

1、安装Ruby 2.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

1、安装Ruby 2.3,参考上面

2、安装依赖包(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

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

1、需要安装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'

2、初始化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

3、创建测试应用程序

[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 

4、客户端访问http://10.1.1.53:3000/

总结

以上就是这篇文章的全部内容了,希望本文的内容对大家的学习或者工作能带来一定的帮助,如果有疑问大家可以留言交流,谢谢大家对我们的支持。

时间: 2017-05-08

CentOS中配置Ruby on Rails环境

详细安装步骤: 一.更新Python centos 中默认安装的python是2.4的版本,因为新版的rails需要提供nodejs的相关支持,需要更新python,更新文章可以直接移步到这个链接 http://www.tomtalk.net/wiki/Python 复制代码 代码如下: yum install -y bzip2*           #nodejs 0.8.5需要,请安装python前,先安装此模块.   wget http://www.python.org/ftp/pytho

CentOS7下搭建ruby on rails开发环境

1.安装rvm curl -L https://get.rvm.io | bash -s stable rvm是一个命令行工具,提供多版本ruby环境的管理和切换,还可以根据项目管理不同的gemset. 如果没有生成ssh key,这一步可能会失败,直接ssh-keygen生成key之后再执行安装即可. 还可能遇到gpg有关的问题:根据提示执行: gpg2 --keyserver hkp://keys.gnupg.net --recv-keys 409B6B1796C275462A1703113

Ubuntu上配置Ruby on Rails框架及RubyMine IDE开发环境

准备阶段的碎碎念 在virtualbox安装过程中由于这样那样的原因,产生许多坑. 坑1.关于终端,一定要使用启动器打开 安装完虚拟机,进入系统,我们便会遇到第一个坑,终端软件,建议大家都使用启动器打开终端, 千万不要使用文件管理器,进入文件夹,再右键"在终端中打开",这个时候,环境变量加载不上,尤其在非桌面文件夹进入时.终端加载不上环境变量,大多的软件都没法在终端中执行. 打开终端时,一定要通过启动器,所谓启动器,就是在bantu中放在桌面左侧的侧边栏,很像windows中的快捷方式

CentOS 6.3下编译安装Ruby 2.0笔记

LINUX操作系统: CentOS6.3 64bit Ruby: ruby-2.0.0-p247 一.安装开发包(使用默认CENTOS更新源) 复制代码 代码如下: # yum install openssl* openssl-devel zlib-devel gcc gcc-c++ make autoconf readline-devel curl-devel expat-devel gettext-devel 二.关闭iptables和SELINUX 复制代码 代码如下: # service

Centos 6.5系统下编译安装PHP 7.0.13的方法

PHP7.0正式版也出来了,今天编译安装了一下,写下安装步骤,我是在centos6.6 环境中编译的,下面是详细的安装步骤 环境依赖 yum install gcc gcc-c++ libxml2 libxml2-python libxml2-devel -y 下载 wget http://cn2.php.net/distributions/php-7.0.13.tar.gz 解压 tar -zxvf php-7.0.13.tar.gz cd php-7.0.13 ./configure --e

CentOS 7.2 下编译安装PHP7.0.10+MySQL5.7.14+Nginx1.10.1的方法详解(mini版本)

一.安装前的准备工作 1.yum update #更新系统 2.yum install gcc gcc-c++ autoconf automake cmake bison m4 libxml2 libxml2-devel libcurl-devel libjpeg-devel libpng-devel libicu-devel #安装php.MySQL.Nngix所依赖的包 3.下载以下包 #我把所有源文件都下载在root目录,读者可自行修改源文件存放目录 3.1 libmcrypt-2.5.8

Linux 环境下编译安装MySQL5.6的笔记记录

一.首先搭建好Linux环境,我这边使用的是redhat enterprise 6.5,并且建议磁盘划分逻辑卷,以便后期的扩容工作. 二.环境搭建好了之后,我们就要去准备MySQL的安装文件,到现在为止mysql仍然是免费开源,可以直接在官网下载,大家可以自行访问官网去下载, 网址是:https://www.mysql.com/downloads/ ,当然下载前大家需要先去注册一个Oracle账户,然后选择社区免费版进行下载. 三.安装依赖包以及cmake编译工具 yum install -y

CentOS 6.4下编译安装MySQL5.6.14教程

概述: CentOS 6.4下通过yum安装的MySQL是5.1版的,比较老,所以就想通过源代码安装高版本的5.6.14. 正文: 一.卸载旧版本 使用下面的命令检查是否安装有MySQL Server rpm -qa | grep mysql 有的话通过下面的命令来卸载掉 rpm -e mysql //普通删除模式 rpm -e --nodeps mysql // 强力删除模式,如果使用上面命令删除时, 提示有依赖的其它文件,则用该命令可以对其进行强力删除 二.安装MySQL 安装编译代码需要的

centos 7系统下编译安装 mysql5.7教程

一.安装约定 mysql安装路径: /usr/local/mysql mysql数据库路径: /data/mysql my配置文件路径: /usr/local/mysql/my.cnf 二.卸载mariadb # rpm -qa | grep mariadb # rpm -e --nodeps mariadb-libs-5.5.37-1.el7_0.x86_64 包名是上一条查询得知 三.创建用户组.用户 添加mysql组 groupadd mysql 添加用户 useradd -g mysql

Linux 6 下编译安装 PHP 5.6实例详解

Linux 6 下编译安装 PHP 5.6实例详解 PHP(外文名:PHP: Hypertext Preprocessor,中文名:"超文本预处理器")是一种通用开源脚本语言.语法吸收了C语言.Java和Perl的特点,利于学习,使用广泛,主要适用于Web开发领域.PHP以其开发源代码,免费,快捷,跨平台,高效,面向对象,强大的动态图像创建等功能深受广大开发者的喜爱.本文描述基于CentOS 6.7下编译安装PHP 5.6.9,同样也适用于CentOS 7下安装. 一.相关依赖包安装

CentOS 7.3.1611编译安装Nginx1.10.3+MySQL5.7.16+PHP7.1.2

前传: 1.CentOS 7.3.1611系统安装配置图解教程 http://www.jb51.net/os/RedHat/597874.html 2.CentOS服务器初始化设置 http://www.jb51.net/article/133839.htm 准备篇 一.防火墙配置 CentOS 7.x默认使用的是firewall作为防火墙,这里改为iptables防火墙. 1.关闭firewall: systemctl stop firewalld.service #停止firewall sy

Centos下编译安装Nginx教程详解

一.安装nginx时必须先安装相应的编译工具 yum -y install gcc gcc-c++ autoconf automake yum -y install zlib zlib-devel openssl openssl-devel pcre-devel 建立nginx 组 groupadd -r nginx useradd -s /sbin/nologin -g nginx -r nginx id nginx zlib:nginx提供gzip模块,需要zlib库支持 openssl:n

CentOS 7下编译安装Nginx 1.11.10教程

前言 之前分享过一篇 CentOS下编译安装nginx及配置缩略图插件的方法教程,当时的环境是 CentOS 6.x 和 Nginx 1.9.x . 本次安装的环境为 CentOS 7.2 和 Nginx 1.11.10, 有些配置以前自启动的方式发生了变化, 这里再记录一下. 安装编译安装依赖的类库和包 yum install gcc gcc-c++ autoconf automake zlib zlib-devel openssl openssl-devel pcre-devel 下载和解压