반응형

     정보

    • 업무명     : 온라인 리눅스 (Linux) 환경에서 R 및 R Studio 설치/업데이트

    • 작성자     : 이상호

    • 작성일     : 2021-01-18

    • 설   명      :

    • 수정이력 :

     

     내용

    [개요]

    • 안녕하세요? 웹 개발 및 연구 개발을 담당하고 있는 해솔입니다.

    • R은 무료 프로그래밍 환경으로 주로 통계 분석에 사용되고 주로 무료 통합 개발 환경 (IDE)인 R Studio를 이용합니다.

    • 오늘 포스팅은 온라인 리눅스 (Linux) 환경에서 R 및 R Studio 설치/업데이트 방법을 소개합니다.

     

     

    [특징]

    • R을 학습하기 위해서 리눅스 환경 구축이 요구되며 이 프로그램은 이러한 목적을 달성하기 위한 소프트웨어

     

    [기능]

    • R 설치/업데이트

    • R Studio 설치/업데이트

     

    [활용 자료]

    • 없음

     

    [자료 처리 방안 및 활용 분석 기법]

    • 없음

     

    [사용법]

    • 세부 내용 참조

     

    [사용 OS]

    • Linux (CentOS v7.3)

    • VMware Workstation Pro v16

     

    [사용 언어]

    • R v4.0.3

    • R Studio v1.4.1103

     

     세부 내용

    [패키지 저장소 추가]

    • yum 명령어를 통해 R을 설치하기 위해 epel 패키지 저장소 추가

    yum install -y epel-release 
    yum update -y

     

    [R 설치]

    • yum 명령어를 통해 설치

    # 설치
    yum install -y R
    
    # 버전 확인
    R --version

     

     

     

    [R Studio 설치]

    • wget 명령어를 통해 다운로드

    • rpm 명령어를 통해 설치 

    # 다운로드
    wget https://download2.rstudio.org/rstudio-server-rhel-1.1.453-x86_64.rpm
    
    # 설치
    rpm -Uvh rstudio-server-rhel-1.1.453-x86_64.rpm

     

     

    [R Studio 확인]

    • systemctl status rstudio-server 명령어를 통해 상태나 활성화 세션 등을 확인

    • 일반적으로 리눅스 서버에 설치한 경우 RStudio가 실행중인 포트 (기본적으로 8787)를 열어 브라우저를 통해 사용

    systemctl status rstudio-server

     

     

    [R Studio 로그인]

    • ifconfig -a 명령어를 통해 서버 ip 확인

     

    • ifconfig -a 명령어를 통해 서버 ip 확인

    • 인터넷 웹 브라우저에서 192.168.11.132:8787를 통해 R Studio 화면을 확인합니다.

    • 계정 접속을 위해 서버 사용자 정보 (이름, 비밀번호)를 입력하여 로그인합니다.

    • RStudio 서버의 경우 보안상의 이유로 root로 로그인이 금지되어 있고 /home 디렉터리에 사용자 계정으로 사용해야 합니다.

    • 예외적으로 vagrant 사용자가 이미 설정되어 있기 때문에 동일한 비밀번호를 입력하고 들어가면 R Studio를 바로 사용할 수도 있습니다.

     

     

    [CRAN에서 패키지 추가]

    • CRAN은 Comprehensive R Archive Network의 약자로 R 패키지를 설치할 수있는 URL 목록 존재

    • 패키지를 설치하는 경우 root 사용자 (sudo 사용)로 R 콘솔을 시작하는 것이 좋음

    • 대기 시간을 최소화하기 위해 다운로드해야 할 미러 위치를 선택하라는 메시지가 표시

    install.packages("txtplot")

     

    [root linux@~]# R
    
    R version 4.0.3 (2020-10-10) -- "Bunny-Wunnies Freak Out"
    Copyright (C) 2020 The R Foundation for Statistical Computing
    Platform: x86_64-pc-linux-gnu (64-bit)
    
    R is free software and comes with ABSOLUTELY NO WARRANTY.
    You are welcome to redistribute it under certain conditions.
    Type 'license()' or 'licence()' for distribution details.
    
      Natural language support but running in an English locale
    
    R is a collaborative project with many contributors.
    Type 'contributors()' for more information and
    'citation()' on how to cite R or R packages in publications.
    
    Type 'demo()' for some demos, 'help()' for on-line help, or
    'help.start()' for an HTML browser interface to help.
    Type 'q()' to quit R.
    
    > install.packages("txtplot")

     

     

    • R Studio 로그인하여 콘솔 창에서도 설치 가능

     

    [R 업데이트]

    • yum 명령어를 통해 이전 버전 (v3.6.0)으로 설치

    • 따라서 최신 버전 (v4.3.0)으로 설치하기 위해 다음과 같이 순서대로 진행

    # 최신 R 설치 파일 읽기
    bash -c "$(curl -L https://rstd.io/r-install)"
    
    # 버전 선택
    4.0.3

     

    [root linux@/SYSTEM/INSTALL/R]# bash -c "$(curl -L https://rstd.io/r-install)"
      % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                     Dload  Upload   Total   Spent    Left  Speed
      0     0    0     0    0     0      0      0 --:--:-- --:--:-- --:--:--     0
    100 12667  100 12667    0     0   8854      0  0:00:01  0:00:01 --:--:--  8854
    Available Versions
      devel
      4.0.3
      4.0.2
      4.0.1
      4.0.0
      3.6.3
      3.6.2
      3.6.1
      3.6.0
      3.5.3
      3.5.2
      3.5.1
      3.5.0
      3.4.4
      3.4.3
      3.4.2
      3.4.1
      3.4.0
      3.3.3
      3.3.2
      3.3.1
      3.3.0
      3.2.5
      3.2.4
      3.2.3
      3.2.2
      3.2.1
      3.2.0
      3.1.3
      3.1.2
      3.1.1
      3.1.0
      3.0.3
      3.0.2
      3.0.1
      3.0.0
    Enter version to install: (<ENTER> for latest)
    4.0.3
    Downloading installer from https://cdn.rstudio.com/r/centos-7/pkgs/R-4.0.3-1-1.x86_64.rpm...
    Downloading https://cdn.rstudio.com/r/centos-7/pkgs/R-4.0.3-1-1.x86_64.rpm...
    --2021-01-26 16:04:54--  https://cdn.rstudio.com/r/centos-7/pkgs/R-4.0.3-1-1.x86_64.rpm
    Resolving cdn.rstudio.com (cdn.rstudio.com)... 52.85.231.63, 52.85.231.31, 52.85.231.15, ...
    Connecting to cdn.rstudio.com (cdn.rstudio.com)|52.85.231.63|:443... connected.
    HTTP request sent, awaiting response... 200 OK
    Length: 58684127 (56M) [binary/octet-stream]
    Saving to: ‘R-4.0.3-1-1.x86_64.rpm’
    
    100%[===============================================================>] 58,684,127  10.7MB/s   in 5.4s   
    
    2021-01-26 16:04:59 (10.4 MB/s) - ‘R-4.0.3-1-1.x86_64.rpm’ saved [58684127/58684127]
    
    User install from RPM installer R-4.0.3-1-1.x86_64.rpm...
    l^H^HLoaded plugins: fastestmirror, langpacks
    epel-release-latest-7.noarch.rpm                                                  |  15 kB  00:00:00     
    Examining /var/tmp/yum-root-U5Qkp0/epel-release-latest-7.noarch.rpm: epel-release-7-13.noarch
    /var/tmp/yum-root-U5Qkp0/epel-release-latest-7.noarch.rpm: does not update installed package.
    Error: Nothing to do
    Updating package indexes...
    Loaded plugins: fastestmirror, langpacks
    Loading mirror speeds from cached hostfile
     * base: mirror.kakao.com
     * epel: ftp.iij.ad.jp
     * extras: mirror.kakao.com
     * nux-dextop: mirror.li.nux.ro
     * updates: mirror.kakao.com
    
    dnsmasq.x86_64                                       2.76-16.el7_9.1                           updates   
    java-1.8.0-openjdk.x86_64                            1:1.8.0.282.b08-1.el7_9                   updates   
    java-1.8.0-openjdk-devel.x86_64                      1:1.8.0.282.b08-1.el7_9                   updates   
    java-1.8.0-openjdk-headless.x86_64                   1:1.8.0.282.b08-1.el7_9                   updates   
    net-snmp-libs.x86_64                                 1:5.7.2-49.el7_9.1                        updates   
    nodejs.x86_64                                        2:14.15.4-1nodesource                     nodesource
    tzdata.noarch                                        2020f-1.el7                               updates   
    tzdata-java.noarch                                   2020f-1.el7                               updates   
    Installing R-4.0.3-1-1.x86_64.rpm...
    Loaded plugins: fastestmirror, langpacks
    Examining R-4.0.3-1-1.x86_64.rpm: R-4.0.3-1-1.x86_64
    R-4.0.3-1-1.x86_64.rpm: does not update installed package.
    Error: Nothing to do

     

    • 설치 완료된 후에 경로 (/opt/R) 버전 (4.0.3)을 확인

     

    • 리눅스 환경 변수 설정

    # 환경 변수 열기
    vi ~/.bashrc
    
    # 환경 변수 추가
    #==========================================
    # Linux Configure
    #==========================================
    # R v4.0.3
    export R=/opt/R/4.0.3
    export R_HOME=/opt/R/4.0.3
    export RSTUDIO_WHICH_R=/opt/R/4.0.3/bin/R
    
    libList=($R)
    
    for i in ${libList[*]}; do
       if [ ! -z $i ]; then
          if [ -d $i/bin ]; then PATH=$i/bin:$PATH ; fi
          if [ -d $i/lib ]; then LD_LIBRARY_PATH=$i/lib:$LD_LIBRARY_PATH ; fi
          if [ -d $i/sbin -a `id -u` = 0 ]; then PATH=$i/sbin:$PATH ; fi
          if [ -d $i/man ]; then MANPATH=$MANPATH:$i/man ; fi
          if [ -d $i/config/lib ]; then PATH=$i/config/lib:$PATH ; fi
          if [ -d $i/config/map ]; then PATH=$i/config/map:$PATH ; fi
       fi
    done

     

    • 리눅스 환경 변수 재 실행

    source ~/.bashrc

     

    • R 버전 확인

    Rscript --version

     

     

    • 심볼릭 링크 생성

    ln -s /opt/R/4.0.3/bin/R /usr/local/bin/R
    ln -s /opt/R/4.0.3/bin/Rscript /usr/local/bin/Rscript

     

    [R Studio 업데이트]

    • 공식 홈페이지에서 Red Hat 7 다운로드

     

     

    Download the RStudio IDE

    RStudio is a set of integrated tools designed to help you be more productive with R. It includes a console, syntax-highlighting editor that supports direct code execution, and a variety of robust tools for plotting, viewing history, debugging and managing

    rstudio.com

     

    • yum 명령어를 통해 설치

    yum -y install rstudio-server-rhel-1.4.1103-x86_64.rpm

     

    • R Studio 버전 확인

     

     참고 문헌

    [논문]

    • 없음

    [보고서]

    • 없음

    [URL]

    • 없음

     

     문의사항

    [기상학/프로그래밍 언어]

    • sangho.lee.1990@gmail.com

    [해양학/천문학/빅데이터]

    • saimang0804@gmail.com
    반응형
    • 네이버 블러그 공유하기
    • 네이버 밴드에 공유하기
    • 페이스북 공유하기
    • 카카오스토리 공유하기