红联Linux门户
Linux帮助

R语言Linux环境安装说明

发布时间:2014-11-21 15:59:54来源:linux网站作者:tianlesoftware

这篇看一下Linux 平台下R 环境的安装。


一. 用YUM解决依赖包问题

R 下载地址:

http://www.r-project.org/

Linux 下的R 安装需要如下rpm包:

[root@rac1 linux_rpm]# ls

libRmath-2.10.0-2.el5.x86_64.rpm        R-core-2.10.0-2.el5.x86_64.rpm

libRmath-devel-2.10.0-2.el5.x86_64.rpm  R-devel-2.10.0-2.el5.x86_64.rpm

R-2.10.0-2.el5.x86_64.rpm

[root@rac1 linux_rpm]# ll

total 32086

-rwxr-xr-x. 1 root root   104394 Mar 4 12:18 libRmath-2.10.0-2.el5.x86_64.rpm

-rwxr-xr-x. 1 root root   151494 Mar 4 12:18 libRmath-devel-2.10.0-2.el5.x86_64.rpm

-rwxr-xr-x. 1 root root    14688 Mar 4 12:18 R-2.10.0-2.el5.x86_64.rpm

-rwxr-xr-x. 1 root root 32495231 Mar  4 12:30 R-core-2.10.0-2.el5.x86_64.rpm

-rwxr-xr-x. 1 root root    88663 Mar 4 12:18 R-devel-2.10.0-2.el5.x86_64.rpm

但是安装这些包会牵涉到很多依赖的包,我们可以使用YUM 来解决这个问题。

用YUM 解决依赖包:

[root@rac1 linux_rpm]# yum install pcre-devel

Loaded plugins: refresh-packagekit

Setting up Install Process

Resolving Dependencies

--> Running transaction check

---> Package pcre-devel.x86_640:7.8-3.1.el6 will be installed

--> Finished Dependency Resolution

Dependencies Resolved

Package                  Arch                 Version                     Repository          Size

Installing:

pcre-devel               x86_64               7.8-3.1.el6                 dave               317 k

Transaction Summary

Install       1 Package(s)

Total download size: 317 k

Installed size: 954 k

Is this ok [y/N]: y

Downloading Packages:

Running rpm_check_debug

Running Transaction Test

Transaction Test Succeeded

Running Transaction

Warning: RPMDB altered outside of yum.

Installing : pcre-devel-7.8-3.1.el6.x86_64                       1/1

Installed:

pcre-devel.x86_64 0:7.8-3.1.el6                                                                 

Complete!

[root@rac1 linux_rpm]# yum install tcl-devel

Loaded plugins: refresh-packagekit

Setting up Install Process

Resolving Dependencies

--> Running transaction check

---> Package tcl-devel.x86_641:8.5.7-6.el6 will be installed

--> Processing Dependency: tcl =1:8.5.7-6.el6 for package: 1:tcl-devel-8.5.7-6.el6.x86_64

--> Processing Dependency:libtcl8.5.so()(64bit) for package: 1:tcl-devel-8.5.7-6.el6.x86_64

--> Running transaction check

---> Package tcl.x86_64 1:8.5.7-6.el6will be installed

--> Finished Dependency Resolution

Dependencies Resolved

Package                 Arch                 Version                      Repository          Size

Installing:

tcl-devel              x86_64               1:8.5.7-6.el6                dave               161 k

Installing for dependencies:

tcl                     x86_64               1:8.5.7-6.el6                dave               1.9 M

Transaction Summary

Install       2 Package(s)

Total download size: 2.1 M

Installed size: 5.1 M

Is this ok [y/N]: y

Downloading Packages:

 

Total                                                               16 MB/s | 2.1 MB     00:00   

Running rpm_check_debug

Running Transaction Test

Transaction Test Succeeded

Running Transaction

Installing : 1:tcl-8.5.7-6.el6.x86_64                                                        1/2

Installing : 1:tcl-devel-8.5.7-6.el6.x86_64                                                  2/2

Installed:

tcl-devel.x86_64 1:8.5.7-6.el6                                                                   

Dependency Installed:

tcl.x86_64 1:8.5.7-6.el6                                                                        

Complete!

You have new mail in /var/spool/mail/root

[root@rac1 linux_rpm]# yum install zlib-devel

Loaded plugins: refresh-packagekit

Setting up Install Process

Resolving Dependencies

--> Running transaction check

---> Package zlib-devel.x86_640:1.2.3-25.el6 will be installed

--> Finished Dependency Resolution

Dependencies Resolved

Package                  Arch                 Version                     Repository          Size

Installing:

zlib-devel               x86_64               1.2.3-25.el6                dave                43 k

Transaction Summary

Install       1 Package(s)

Total download size: 43 k

Installed size: 115 k

Is this ok [y/N]: y

Downloading Packages:

Running rpm_check_debug

Running Transaction Test

Transaction Test Succeeded

Running Transaction

Installing : zlib-devel-1.2.3-25.el6.x86_64                                                  1/1

Installed:

zlib-devel.x86_64 0:1.2.3-25.el6                                                                

Coplete!

[root@rac1 linux_rpm]# yum install bzip2-devel

Loaded plugins: refresh-packagekit

Setting up Install Process

Resolving Dependencies

--> Running transaction check

---> Package bzip2-devel.x86_640:1.0.5-7.el6_0 will be installed

--> Finished Dependency Resolution

Dependencies Resolved

Package                  Arch                Version                       Repository         Size

Installing:

bzip2-devel              x86_64              1.0.5-7.el6_0                 dave              250 k

Transaction Summary

Install       1 Package(s)

Total download size: 250 k

Installed size: 412 k

Is this ok [y/N]: y

Downloading Packages:

Running rpm_check_debug

Running Transaction Test

Transaction Test Succeeded

Running Transaction

Installing : bzip2-devel-1.0.5-7.el6_0.x86_64                                                1/1

Installed:

 bzip2-devel.x86_640:1.0.5-7.el6_0                                                              

Complete!

[root@rac1 linux_rpm]# yum install libX11-devel

Loaded plugins: refresh-packagekit

Setting up Install Process

Resolving Dependencies

--> Running transaction check

---> Package libX11-devel.x86_640:1.3-2.el6 will be installed

--> Processing Dependency:pkgconfig(xcb) >= 1.1.92 for package: libX11-devel-1.3-2.el6.x86_64

--> Processing Dependency: libXau-develfor package: libX11-devel-1.3-2.el6.x86_64

--> Processing Dependency:pkgconfig(kbproto) for package: libX11-devel-1.3-2.el6.x86_64

--> Processing Dependency:pkgconfig(xcb) for package: libX11-devel-1.3-2.el6.x86_64

--> Processing Dependency:libXdmcp-devel for package: libX11-devel-1.3-2.el6.x86_64

--> Processing Dependency:pkgconfig(xproto) for package: libX11-devel-1.3-2.el6.x86_64

--> Running transaction check

---> Package libXau-devel.x86_640:1.0.5-1.el6 will be installed

---> Package libXdmcp-devel.x86_640:1.0.3-1.el6 will be installed

---> Package libxcb-devel.x86_640:1.5-1.el6 will be installed

---> Package xorg-x11-proto-devel.noarch0:7.4-35.el6 will be installed

--> Finished Dependency Resolution

Dependencies Resolved

Package                          Arch               Version                 Repository        Size

Installing:

libX11-devel                     x86_64             1.3-2.el6               dave             1.0 M

Installing for dependencies:

libXau-devel                     x86_64             1.0.5-1.el6             dave              13 k

libXdmcp-devel                   x86_64             1.0.3-1.el6             dave             9.1 k

libxcb-devel                     x86_64             1.5-1.el6               dave             138 k

xorg-x11-proto-devel             noarch             7.4-35.el6              dave             249 k

Transaction Summary

Install       5 Package(s)

Total download size: 1.4 M

Installed size: 4.5 M

Is this ok [y/N]: y

Downloading Packages:

Total                                                               10 MB/s | 1.4 MB     00:00   

Running rpm_check_debug

Running Transaction Test

Transaction Test Succeeded

Running Transaction

Installing : xorg-x11-proto-devel-7.4-35.el6.noarch                                           1/5

Installing : libXau-devel-1.0.5-1.el6.x86_64                                                 2/5

Installing : libxcb-devel-1.5-1.el6.x86_64                                                   3/5

Installing : libXdmcp-devel-1.0.3-1.el6.x86_64                                               4/5

Installing : libX11-devel-1.3-2.el6.x86_64                                                    5/5

Installed:

libX11-devel.x86_64 0:1.3-2.el6                                                                 

Dependency Installed:

libXau-devel.x86_64 0:1.0.5-1.el6             libXdmcp-devel.x86_640:1.0.3-1.el6                

libxcb-devel.x86_64 0:1.5-1.el6               xorg-x11-proto-devel.noarch0:7.4-35.el6          

Complete!

You have new mail in /var/spool/mail/root

[root@rac1 linux_rpm]# yum install tk-devel

Loaded plugins: refresh-packagekit

Setting up Install Process

Resolving Dependencies

--> Running transaction check

---> Package tk-devel.x86_641:8.5.7-5.el6 will be installed

--> Processing Dependency: tk =1:8.5.7-5.el6 for package: 1:tk-devel-8.5.7-5.el6.x86_64

--> Processing Dependency: libXft-develfor package: 1:tk-devel-8.5.7-5.el6.x86_64

--> Processing Dependency:libtk8.5.so()(64bit) for package: 1:tk-devel-8.5.7-5.el6.x86_64

--> Running transaction check

---> Package libXft-devel.x86_640:2.1.13-4.1.el6 will be installed

--> Processing Dependency:fontconfig-devel >= 2.2-1 for package: libXft-devel-2.1.13-4.1.el6.x86_64

--> Processing Dependency:freetype-devel >= 2.1.9-2 for package: libXft-devel-2.1.13-4.1.el6.x86_64

--> Processing Dependency:pkgconfig(xrender) for package: libXft-devel-2.1.13-4.1.el6.x86_64

--> Processing Dependency:pkgconfig(freetype2) for package: libXft-devel-2.1.13-4.1.el6.x86_64

--> Processing Dependency:pkgconfig(fontconfig) for package: libXft-devel-2.1.13-4.1.el6.x86_64

--> Processing Dependency: libXrender-develfor package: libXft-devel-2.1.13-4.1.el6.x86_64

---> Package tk.x86_64 1:8.5.7-5.el6will be installed

--> Running transaction check

---> Package fontconfig-devel.x86_640:2.8.0-3.el6 will be installed

---> Package freetype-devel.x86_640:2.3.11-6.el6_0.2 will be installed

---> Package libXrender-devel.x86_640:0.9.5-1.el6 will be installed

--> Finished Dependency Resolution

Dependencies Resolved

Package                     Arch              Version                        Repository       Size

Installing:

tk-devel                    x86_64            1:8.5.7-5.el6                  dave            496 k

Installing for dependencies:

fontconfig-devel            x86_64            2.8.0-3.el6                    dave            209 k

freetype-devel              x86_64            2.3.11-6.el6_0.2               dave            362 k

libXft-devel                x86_64            2.1.13-4.1.el6                 dave             18 k

libXrender-devel            x86_64            0.9.5-1.el6                    dave             15 k

tk                          x86_64            1:8.5.7-5.el6                  dave            1.4 M

Transaction Summary

Install       6 Package(s)

Total download size: 2.5 M

Installed size: 7.4 M

Is this ok [y/N]: y

Downloading Packages:

Total                                                               13 MB/s | 2.5 MB     00:00   

Running rpm_check_debug

Running Transaction Test

Transaction Test Succeeded

Running Transaction

Installing : freetype-devel-2.3.11-6.el6_0.2.x86_64                                           1/6

Installing : fontconfig-devel-2.8.0-3.el6.x86_64                                             2/6

Installing : 1:tk-8.5.7-5.el6.x86_64                                                         3/6

Installing : libXrender-devel-0.9.5-1.el6.x86_64                                              4/6

Installing : libXft-devel-2.1.13-4.1.el6.x86_64                                              5/6

Installing : 1:tk-devel-8.5.7-5.el6.x86_64                                                   6/6

Installed:

 tk-devel.x86_641:8.5.7-5.el6                                                                   

Dependency Installed:

fontconfig-devel.x86_64 0:2.8.0-3.el6           freetype-devel.x86_640:2.3.11-6.el6_0.2        

libXft-devel.x86_64 0:2.1.13-4.1.el6            libXrender-devel.x86_640:0.9.5-1.el6           

tk.x86_64 1:8.5.7-5.el6                      

Complete!

[root@rac1 linux_rpm]# yum install tetex-latex

Loaded plugins: refresh-packagekit

Setting up Install Process

Resolving Dependencies

--> Running transaction check

---> Package texlive-latex.x86_640:2007-56.el6 will be installed

--> Processing Dependency: texlive-dvips= 2007-56.el6 for package: texlive-latex-2007-56.el6.x86_64

--> Processing Dependency: texlive-texmf-errata= 2007 for package: texlive-latex-2007-56.el6.x86_64

--> Processing Dependency: texlive =2007-56.el6 for package: texlive-latex-2007-56.el6.x86_64

--> Processing Dependency: texlive-utils= 2007-56.el6 for package: texlive-latex-2007-56.el6.x86_64

--> Processing Dependency:texlive-texmf-latex = 2007 for package: texlive-latex-2007-56.el6.x86_64

--> Processing Dependency:/usr/bin/fmtutil-sys for package: texlive-latex-2007-56.el6.x86_64

--> Processing Dependency:/usr/bin/fmtutil for package: texlive-latex-2007-56.el6.x86_64

--> Processing Dependency: netpbm-progsfor package: texlive-latex-2007-56.el6.x86_64

--> Processing Dependency:/usr/bin/texconfig-sys for package: texlive-latex-2007-56.el6.x86_64

--> Running transaction check

---> Package netpbm-progs.x86_640:10.47.05-11.el6 will be installed

--> Processing Dependency: netpbm =10.47.05-11.el6 for package: netpbm-progs-10.47.05-11.el6.x86_64

--> Processing Dependency:libnetpbm.so.10()(64bit) for package: netpbm-progs-10.47.05-11.el6.x86_64

---> Package texlive.x86_640:2007-56.el6 will be installed

--> Processing Dependency:texlive-texmf-fonts = 2007 for package: texlive-2007-56.el6.x86_64

--> Processing Dependency: texlive-texmf= 2007 for package: texlive-2007-56.el6.x86_64

--> Processing Dependency:libkpathsea.so.4()(64bit) for package: texlive-2007-56.el6.x86_64

---> Package texlive-dvips.x86_640:2007-56.el6 will be installed

--> Processing Dependency:texlive-texmf-dvips = 2007 for package: texlive-dvips-2007-56.el6.x86_64

--> Processing Dependency: psutils forpackage: texlive-dvips-2007-56.el6.x86_64

---> Package texlive-texmf-errata.noarch0:2007-7.1.el6 will be installed

---> Package texlive-texmf-latex.noarch0:2007-35.el6 will be installed

--> Processing Dependency:texlive-texmf-errata-latex = 2007 for package:texlive-texmf-latex-2007-35.el6.noarch

--> Processing Dependency: tex-previewfor package: texlive-texmf-latex-2007-35.el6.noarch

---> Package texlive-utils.x86_640:2007-56.el6 will be installed

--> Running transaction check

---> Package kpathsea.x86_640:2007-56.el6 will be installed

---> Package netpbm.x86_640:10.47.05-11.el6 will be installed

---> Package psutils.x86_640:1.17-34.el6 will be installed

---> Package tex-preview.noarch 0:11.85-10.el6will be installed

---> Package texlive-texmf.noarch0:2007-35.el6 will be installed

---> Package texlive-texmf-dvips.noarch0:2007-35.el6 will be installed

--> Processing Dependency:texlive-texmf-errata-dvips = 2007 for package: texlive-texmf-dvips-2007-35.el6.noarch

---> Packagetexlive-texmf-errata-latex.noarch 0:2007-7.1.el6 will be installed

---> Package texlive-texmf-fonts.noarch0:2007-35.el6 will be installed

--> Processing Dependency:texlive-texmf-errata-fonts = 2007 for package: texlive-texmf-fonts-2007-35.el6.noarch

--> Running transaction check

---> Packagetexlive-texmf-errata-dvips.noarch 0:2007-7.1.el6 will be installed

---> Packagetexlive-texmf-errata-fonts.noarch 0:2007-7.1.el6 will be installed

--> Finished Dependency Resolution

Dependencies Resolved

Package                             Arch            Version                    Repository     Size

Installing:

texlive-latex                       x86_64          2007-56.el6                dave           82 k

Installing for dependencies:

kpathsea                           x86_64          2007-56.el6                dave          117 k

netpbm                              x86_64          10.47.05-11.el6            dave          802 k

netpbm-progs                        x86_64          10.47.05-11.el6            dave          1.7 M

psutils                             x86_64          1.17-34.el6                dave           46 k

tex-preview                         noarch          11.85-10.el6               dave           49 k

texlive                             x86_64          2007-56.el6                dave          1.8 M

texlive-dvips                       x86_64          2007-56.el6                dave          193 k

texlive-texmf                       noarch          2007-35.el6                dave          2.8 M

texlive-texmf-dvips                 noarch          2007-35.el6                dave          237 k

texlive-texmf-errata                noarch          2007-7.1.el6               dave          4.8 k

texlive-texmf-errata-dvips          noarch          2007-7.1.el6               dave          4.8 k

 texlive-texmf-errata-fonts          noarch          2007-7.1.el6               dave          5.0 k

 texlive-texmf-errata-latex          noarch          2007-7.1.el6               dave          4.9 k

 texlive-texmf-fonts                 noarch          2007-35.el6                dave           48 M

 texlive-texmf-latex                 noarch          2007-35.el6                dave          5.3 M

 texlive-utils                       x86_64          2007-56.el6                dave          253 k

Transaction Summary

Install     17 Package(s)

Total download size: 62 M

Installed size: 162 M

Is this ok [y/N]: y

Downloading Packages:

Total                                                               38 MB/s |  62 MB     00:01   

Running rpm_check_debug

Running Transaction Test

Transaction Test Succeeded

Running Transaction

 Installing : texlive-texmf-errata-2007-7.1.el6.noarch                                        1/17

 Installing : texlive-texmf-2007-35.el6.noarch                                                2/17

 Installing : kpathsea-2007-56.el6.x86_64                                                    3/17

 Installing : texlive-texmf-errata-fonts-2007-7.1.el6.noarch                                  4/17

 Installing : netpbm-10.47.05-11.el6.x86_64                                                  5/17

 Installing : netpbm-progs-10.47.05-11.el6.x86_64                                            6/17

 Installing : texlive-texmf-errata-dvips-2007-7.1.el6.noarch                                  7/17

 Installing : texlive-texmf-dvips-2007-35.el6.noarch                                          8/17

 Installing : texlive-texmf-fonts-2007-35.el6.noarch                                          9/17

 Installing : texlive-2007-56.el6.x86_64                                                    10/17

 Installing : texlive-texmf-errata-latex-2007-7.1.el6.noarch                                 11/17

 Installing : psutils-1.17-34.el6.x86_64                                                     12/17

 Installing : texlive-dvips-2007-56.el6.x86_64                                              13/17

 Installing : texlive-utils-2007-56.el6.x86_64                                              14/17

 Installing : texlive-texmf-latex-2007-35.el6.noarch                                         15/17

 Installing : texlive-latex-2007-56.el6.x86_64                                              16/17

 Installing : tex-preview-11.85-10.el6.noarch                                                17/17

Installed:

 texlive-latex.x86_64 0:2007-56.el6                                                              

Dependency Installed:

 kpathsea.x86_64 0:2007-56.el6                    netpbm.x86_640:10.47.05-11.el6               

  netpbm-progs.x86_640:10.47.05-11.el6           psutils.x86_64 0:1.17-34.el6                  

 tex-preview.noarch 0:11.85-10.el6                texlive.x86_640:2007-56.el6                  

 texlive-dvips.x86_64 0:2007-56.el6               texlive-texmf.noarch0:2007-35.el6            

 texlive-texmf-dvips.noarch 0:2007-35.el6         texlive-texmf-errata.noarch0:2007-7.1.el6    

 texlive-texmf-errata-dvips.noarch 0:2007-7.1.el6texlive-texmf-errata-fonts.noarch 0:2007-7.1.el6

 texlive-texmf-errata-latex.noarch 0:2007-7.1.el6texlive-texmf-fonts.noarch 0:2007-35.el6      

 texlive-texmf-latex.noarch 0:2007-35.el6         texlive-utils.x86_640:2007-56.el6            

Complete!

You have new mail in /var/spool/mail/root

[root@rac1 linux_rpm]#


二.开始安装R
2.1 安装llibRmath包

这2个包没什么依赖,好安装

[root@rac1 linux_rpm]# rpm -ivhlibRmath-2.10.0-2.el5.x86_64.rpm

warning: libRmath-2.10.0-2.el5.x86_64.rpm:Header V3 DSA/SHA1 Signature, key ID 97d3544e: NOKEY

Preparing...                ###########################################[100%]

  1:libRmath              ########################################### [100%]

[root@rac1 linux_rpm]# rpm -ivhlibRmath-devel-2.10.0-2.el5.x86_64.rpm

warning:libRmath-devel-2.10.0-2.el5.x86_64.rpm: Header V3 DSA/SHA1 Signature, key ID97d3544e: NOKEY

Preparing...               ########################################### [100%]

1:libRmath-devel        ########################################### [100%]

[root@rac1 linux_rpm]#
 
2.2 安装R-core,这个要先安装:

[root@rac1 linux_rpm]# rpm -Uvh R-core-2.10.0-2.el5.x86_64.rpm

warning: R-core-2.10.0-2.el5.x86_64.rpm:Header V3 DSA/SHA1 Signature, key ID 97d3544e: NOKEY

error: Failed dependencies:

libtcl8.4.so()(64bit) is needed by R-core-2.10.0-2.el5.x86_64

libtk8.4.so()(64bit) is needed by R-core-2.10.0-2.el5.x86_64

perl(File::Copy::Recursive) is needed by R-core-2.10.0-2.el5.x86_64

--这里安装报错,说要8.4 的tcl 包,实际我们已经通过yum安装了8.5的,所以这里我们可以强制安装。

[root@rac1 linux_rpm]# rpm -qa|grep tcl

tcl-devel-8.5.7-6.el6.x86_64

tcl-8.5.7-6.el6.x86_64

强制安装R-core:

[root@rac1 linux_rpm]# rpm -Uvh R-core-2.10.0-2.el5.x86_64.rpm --force --nodeps

warning: R-core-2.10.0-2.el5.x86_64.rpm:Header V3 DSA/SHA1 Signature, key ID 97d3544e: NOKEY

Preparing...                ###########################################[100%]

1:R-core                ########################################### [100%]

2.3 安装R-devel

[root@rac1 linux_rpm]# rpm -ivh R-devel-2.10.0-2.el5.x86_64.rpm

warning: R-devel-2.10.0-2.el5.x86_64.rpm:Header V3 DSA/SHA1 Signature, key ID 97d3544e: NOKEY

Preparing...               ########################################### [100%]

1:R-devel               ########################################### [100%]

2.4 最后安装R

[root@rac1 linux_rpm]# rpm -ivh R-2.10.0-2.el5.x86_64.rpm

warning: R-2.10.0-2.el5.x86_64.rpm: HeaderV3 DSA/SHA1 Signature, key ID 97d3544e: NOKEY

Preparing...               ########################################### [100%]

1:R                     ########################################### [100%]

You have new mail in /var/spool/mail/root

[root@rac1 linux_rpm]#

至此,R 环境安装完毕。


三.测试

继续Windows 下的测试用例:

[root@rac1 ~]# xhost +

access control disabled, clients canconnect from any host

[root@rac1 ~]# R

R version 2.10.0 (2009-10-26)

Copyright (C) 2009 The R Foundation forStatistical Computing

ISBN 3-900051-07-0

R is free software and comes withABSOLUTELY NO WARRANTY.

You are welcome to redistribute it undercertain conditions.

Type 'license()' or 'licence()' fordistribution details.

Natural language support but running in an English locale

R is a collaborative project with manycontributors.

Type 'contributors()' for more informationand

'citation()' on how to cite R or R packagesin publications.

Type 'demo()' for some demos, 'help()' foron-line help, or

'help.start()' for an HTML browserinterface to help.

Type 'q()' to quit R.

>vol=trees[["Girth"]]^2*trees[["Height"]]/(4*pi)

> hist(vol,col=1)

>

然后弹出窗口。