Install Ruby on RHEL6
安装Ruby有两种方式选择:YUM安装;源码包安装。
YUM的安装方式非常简单:
1. 配置好YUM环境
2. yum install -y ruby
本文主要介绍源码包的安装方式。
在开始前,你需要确认你的Linux环境安装了需要的软件包:
yum install -y tk gcc gcc-c++ zlib zlib-devel readline readline-devel openssl openssl-devel
Ruby的官方网站:http://www.ruby-lang.org/zh_cn/
官方下载页:http://www.ruby-lang.org/zh_cn/downloads/
在官方下载页面里,你可以找到Ruby的源码包:
当前稳定版 – 2.3.0
Link:
https://cache.ruby-lang.org/pub/ruby/2.3/ruby-2.3.0.tar.gz
1. 在目标服务器上下载Ruby的源码包:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 |
[root@LinuxWebServer ~]# cd /tmp/ [root@LinuxWebServer tmp]# ls ks-script-QdTSFL ks-script-QdTSFL.log orbit-gdm pulse-CZyKN0DkbzXD yum.log [root@LinuxWebServer tmp]# [root@LinuxWebServer tmp]# wget https://cache.ruby-lang.org/pub/ruby/2.3/ruby-2.3.0.tar.gz --2016-03-06 02:44:16-- https://cache.ruby-lang.org/pub/ruby/2.3/ruby-2.3.0.tar.gz Resolving cache.ruby-lang.org... 103.245.222.233 Connecting to cache.ruby-lang.org|103.245.222.233|:443... connected. HTTP request sent, awaiting response... 200 OK Length: 17648682 (17M) [application/octet-stream] Saving to: “ruby-2.3.0.tar.gz” 100%[======================================================================================================================>] 17,648,682 222K/s in 1m 50s 2016-03-06 02:46:09 (157 KB/s) - “ruby-2.3.0.tar.gz” saved [17648682/17648682] [root@LinuxWebServer tmp]# ls ks-script-QdTSFL ks-script-QdTSFL.log orbit-gdm pulse-CZyKN0DkbzXD ruby-2.3.0.tar.gz yum.log [root@LinuxWebServer tmp]# |
2. 解压源码包:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 |
[root@LinuxWebServer tmp]# tar xzf ruby-2.3.0.tar.gz [root@LinuxWebServer tmp]# ls ks-script-QdTSFL ks-script-QdTSFL.log orbit-gdm pulse-CZyKN0DkbzXD ruby-2.3.0 ruby-2.3.0.tar.gz yum.log [root@LinuxWebServer tmp]# [root@LinuxWebServer tmp]# cd ruby-2.3.0 [root@LinuxWebServer ruby-2.3.0]# ls aclocal.m4 CONTRIBUTING.md error.c id_table.h Makefile.in parse.c regenc.h string.c version.h addr2line.c COPYING eval.c include man parse.h regerror.c struct.c vm_args.c addr2line.h COPYING.ja eval_error.c inits.c marshal.c parse.y regexec.c symbol.c vm_backtrace.c array.c coverage eval_intern.h insns.def math.c prelude.c regint.h symbol.h vm.c benchmark cygwin eval_jump.c insns.inc method.h prelude.rb regparse.c template vm_call_iseq_optimized.inc bignum.c debug.c ext insns_info.inc miniinit.c probes.d regparse.h test vm_core.h bin defs file.c internal.h miniprelude.c probes.dmyh regsyntax.c thread.c vm_debug.h bootstraptest dir.c gc.c io.c misc probes_helper.h revision.h thread_pthread.c vm_dump.c BSDL dln.c gc.h iseq.c missing proc.c ruby_atomic.h thread_pthread.h vm_eval.c ccan dln_find.c gem_prelude.rb iseq.h nacl process.c ruby.c thread_sync.c vm_exec.c ChangeLog dln.h gems KNOWNBUGS.rb NEWS random.c safe.c thread_win32.c vm_exec.h class.c dmydln.c golf_prelude.c known_errors.inc node.c range.c sample thread_win32.h vm.inc common.mk dmyenc.c golf_prelude.rb LEGAL node.h rational.c signal.c time.c vm_insnhelper.c compar.c dmyext.c goruby.c lex.c node_name.inc README.EXT siphash.c timev.h vm_insnhelper.h compile.c doc GPL lex.c.blt numeric.c README.EXT.ja siphash.h tool vm_method.c complex.c enc hash.c lib object.c README.ja.md sparc.c transcode.c vm_opts.h configure encindex.h ia64.s load.c optinsn.inc README.md spec transcode_data.h vmtc.inc configure.in encoding.c id.c loadpath.c opt_sc.inc re.c sprintf.c util.c vm_trace.c constant.h enum.c id.h localeinit.c optunifs.inc regcomp.c st.c variable.c vsnprintf.c cont.c enumerator.c id_table.c main.c pack.c regenc.c strftime.c version.c win32 [root@LinuxWebServer ruby-2.3.0]# |
3. 创建要安装到的目录:/usr/local/ruby
1 2 |
[root@LinuxWebServer ruby-2.3.0]# mkdir /usr/local/ruby [root@LinuxWebServer ruby-2.3.0]# |
4. 编译
./configure
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 |
[root@LinuxWebServer ruby-2.3.0]# ls -l | grep --color configure -rwxr-xr-x 1 1001 wheel 669724 Dec 25 00:44 configure -rw-r--r-- 1 1001 wheel 143109 Dec 23 13:29 configure.in [root@LinuxWebServer ruby-2.3.0]# [root@LinuxWebServer ruby-2.3.0]# ./configure --prefix=/usr/local/ruby (... ... 过多的输出) checking valgrind/memcheck.h presence... no checking for valgrind/memcheck.h... no checking for strip... strip checking whether -fPIE is accepted as CFLAGS... yes checking whether -pie is accepted as LDFLAGS... yes checking whether wrapper for LD_LIBRARY_PATH is needed... no checking for __builtin_setjmp... yes with cast () checking for setjmp type... __builtin_setjmp checking for prefix of external symbols... NONE checking pthread.h usability... yes checking pthread.h presence... yes checking for pthread.h... yes checking if make is GNU make... yes checking for nroff... /usr/bin/nroff .ext/include/x86_64-linux/ruby/config.h updated configure: ruby library version = 2.3.0 configure: creating ./config.status config.status: creating GNUmakefile config.status: creating Makefile config.status: creating ruby-2.3.pc [root@LinuxWebServer ruby-2.3.0]# |
注意,如果Linux环境中,没有如文首那样安装gcc的软件包,则在编译的这一步,你可能遇到如下的错误现象:
1 2 3 4 5 6 7 8 9 10 11 12 |
[root@LinuxWebServer ruby-2.3.0]# ./configure --prefix=/usr/local/ruby checking for ruby... false checking build system type... x86_64-pc-linux-gnu checking host system type... x86_64-pc-linux-gnu checking target system type... x86_64-pc-linux-gnu checking for gcc... no checking for cc... no checking for cl.exe... no configure: error: in `/tmp/ruby-2.3.0': configure: error: no acceptable C compiler found in $PATH See `config.log' for more details [root@LinuxWebServer ruby-2.3.0]# |
5. make:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 |
[root@LinuxWebServer ruby-2.3.0]# make (... ... 过多的输出) make[2]: Nothing to be done for `all'. make[2]: Leaving directory `/tmp/ruby-2.3.0/ext/tk/tkutil' make[2]: Entering directory `/tmp/ruby-2.3.0/ext/zlib' make[2]: Nothing to be done for `all'. make[2]: Leaving directory `/tmp/ruby-2.3.0/ext/zlib' make[2]: Entering directory `/tmp/ruby-2.3.0' linking ruby make[2]: Leaving directory `/tmp/ruby-2.3.0' make[1]: Leaving directory `/tmp/ruby-2.3.0' Generating RDoc documentation Parsing sources... 100% [945/945] vsnprintf.c Generating RI format into /tmp/ruby-2.3.0/.ext/rdoc... Files: 945 Classes: 1401 ( 576 undocumented) Modules: 280 ( 110 undocumented) Constants: 2172 ( 604 undocumented) Attributes: 1144 ( 255 undocumented) Methods: 10511 (2230 undocumented) Total: 15508 (3775 undocumented) 75.66% documented Elapsed: 85.6s [root@LinuxWebServer ruby-2.3.0]# |
6. make install:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 |
[root@LinuxWebServer ruby-2.3.0]# make install CC = gcc LD = ld LDSHARED = gcc -shared CFLAGS = -O3 -fno-fast-math -ggdb3 -Wall -Wextra -Wno-unused-parameter -Wno-parentheses -Wno-long-long -Wno-missing-field-initializers -Wunused-variable -Wpointer-arith -Wwrite-strings -Wdeclaration-after-statement -Wimplicit-function-declaration -Wdeprecated-declarations -Wno-packed-bitfield-compat -std=iso9899:1999 XCFLAGS = -D_FORTIFY_SOURCE=2 -fstack-protector -fno-strict-overflow -fvisibility=hidden -DRUBY_EXPORT -fPIE CPPFLAGS = -I. -I.ext/include/x86_64-linux -I./include -I. DLDFLAGS = -fstack-protector -pie SOLIBS = Using built-in specs. Target: x86_64-redhat-linux Configured with: ../configure --prefix=/usr --mandir=/usr/share/man --infodir=/usr/share/info --with-bugurl=http://bugzilla.redhat.com/bugzilla --enable-bootstrap --enable-shared --enable-threads=posix --enable-checking=release --with-system-zlib --enable-__cxa_atexit --disable-libunwind-exceptions --enable-gnu-unique-object --enable-languages=c,c++,objc,obj-c++,java,fortran,ada --enable-java-awt=gtk --disable-dssi --with-java-home=/usr/lib/jvm/java-1.5.0-gcj-1.5.0.0/jre --enable-libgcj-multifile --enable-java-maintainer-mode --with-ecj-jar=/usr/share/java/eclipse-ecj.jar --disable-libjava-multilib --with-ppl --with-cloog --with-tune=generic --with-arch_32=i686 --build=x86_64-redhat-linux Thread model: posix gcc version 4.4.7 20120313 (Red Hat 4.4.7-11) (GCC) generating enc.mk making enc make[1]: Entering directory `/tmp/ruby-2.3.0' make[1]: Nothing to be done for `enc'. make[1]: Leaving directory `/tmp/ruby-2.3.0' making srcs under enc make[1]: Entering directory `/tmp/ruby-2.3.0' (... ... 过多的输出) make[1]: Leaving directory `/tmp/ruby-2.3.0' Generating RDoc documentation No newer files. Files: 0 Classes: 0 (0 undocumented) Modules: 0 (0 undocumented) Constants: 0 (0 undocumented) Attributes: 0 (0 undocumented) Methods: 0 (0 undocumented) Total: 0 (0 undocumented) 0.00% documented Elapsed: 0.0s generating x86_64-linux-fake.rb x86_64-linux-fake.rb updated ./miniruby -I./lib -I. -I.ext/common ./tool/runruby.rb --extout=.ext -- --disable-gems -r./x86_64-linux-fake ./tool/rbinstall.rb --make="make" --dest-dir="" --extout=".ext" --mflags="" --make-flags="" --data-mode=0644 --prog-mode=0755 --installed-list .installed.list --mantype="doc" --install=all --rdoc-output=".ext/rdoc" installing binary commands: /usr/local/ruby/bin installing base libraries: /usr/local/ruby/lib installing arch files: /usr/local/ruby/lib/ruby/2.3.0/x86_64-linux installing pkgconfig data: /usr/local/ruby/lib/pkgconfig installing command scripts: /usr/local/ruby/bin installing library scripts: /usr/local/ruby/lib/ruby/2.3.0 installing common headers: /usr/local/ruby/include/ruby-2.3.0 installing manpages: /usr/local/ruby/share/man/man1 installing extension objects: /usr/local/ruby/lib/ruby/2.3.0/x86_64-linux installing extension objects: /usr/local/ruby/lib/ruby/site_ruby/2.3.0/x86_64-linux installing extension objects: /usr/local/ruby/lib/ruby/vendor_ruby/2.3.0/x86_64-linux installing extension headers: /usr/local/ruby/include/ruby-2.3.0/x86_64-linux installing extension scripts: /usr/local/ruby/lib/ruby/2.3.0 installing extension scripts: /usr/local/ruby/lib/ruby/site_ruby/2.3.0 installing extension scripts: /usr/local/ruby/lib/ruby/vendor_ruby/2.3.0 installing extension headers: /usr/local/ruby/include/ruby-2.3.0/ruby installing default gems: /usr/local/ruby/lib/ruby/gems/2.3.0 (build_info, cache, doc, extensions, gems, specifications) bigdecimal 1.2.8 io-console 0.4.5 json 1.8.3 psych 2.0.17 rdoc 4.2.1 installing bundle gems: /usr/local/ruby/lib/ruby/gems/2.3.0 (build_info, cache, doc, extensions, gems, specifications) net-telnet 0.1.1 did_you_mean 1.0.0 test-unit 3.1.5 minitest 5.8.3 rake 10.4.2 power_assert 0.2.6 installing rdoc: /usr/local/ruby/share/ri/2.3.0/system installing capi-docs: /usr/local/ruby/share/doc/ruby [root@LinuxWebServer ruby-2.3.0]# |
7. 将Ruby写入环境变量PATH:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 |
[root@LinuxWebServer ruby-2.3.0]# ls /usr/local/ruby/ bin include lib share [root@LinuxWebServer ruby-2.3.0]# [root@LinuxWebServer ~]# vi /root/.bash_profile [root@LinuxWebServer ~]# cat /root/.bash_profile # .bash_profile # Get the aliases and functions if [ -f ~/.bashrc ]; then . ~/.bashrc fi # User specific environment and startup programs PATH=$PATH:$HOME/bin:/usr/local/ruby/bin export PATH [root@LinuxWebServer ~]# [root@LinuxWebServer ~]# source .bash_profile [root@LinuxWebServer ~]# [root@LinuxWebServer ~]# whereis ruby ruby: /usr/local/ruby [root@LinuxWebServer ~]# [root@LinuxWebServer ~]# ruby -v ruby 2.3.0p0 (2015-12-25 revision 53290) [x86_64-linux] [root@LinuxWebServer ~]# |
8. 使用:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 |
[root@LinuxWebServer ~]# irb irb(main):001:0> "Hello world" => "Hello world" irb(main):002:0> puts "Hi, Angelababy" Hi, Angelababy => nil irb(main):003:0> exit [root@LinuxWebServer ~]# [root@LinuxWebServer ~]# irb irb(main):001:0> "Hello world" => "Hello world" irb(main):002:0> irb(main):003:0* puts "Hi angelababy" Hi angelababy => nil irb(main):004:0> 5+6 => 11 irb(main):005:0> exit [root@LinuxWebServer ~]# |
————————————————————
Done。