日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

CentOS 7 配置Ruby语言开发环境

發布時間:2023/12/18 编程问答 35 豆豆
生活随笔 收集整理的這篇文章主要介紹了 CentOS 7 配置Ruby语言开发环境 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

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_installationNOTE: RUNNING ALL PARTS OF THIS SCRIPT IS RECOMMENDED FOR ALL MariaDBSERVERS 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 ServerCopyright (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: &defaultadapter: mysql2encoding: utf8pool: 5username: rootpassword: password # MariaDB passwordsocket: /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语言开发环境的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。