Install R/RStudio/RStudio Server on Ubuntu 20.04 Server

​Record : The author is a computer novice, but recently under the guidance of a Tongji teacher, I have carried out a bioinformatics-related project (related to the classification of genotypes at the single-cell level), which was originally carried out on a local computer, but the complex I found an article code on NC, and found that a case consumes such a large amount of memory, so I switched from the local desktop to install R in the Ubuntu server, which can have a CPU with larger memory. And this article is the first record of my own learning of R. It mainly describes how to install R / RStudio / RStudio Server on the school server - Ubuntu 20.04, and encourages myself to study hard.


1. Simple understanding of R / RStudio / RStudio Server

R : R is a language and operating environment for statistical analysis and graphics. R is a free, free, and open-source software belonging to the GNU system. It is an excellent tool for statistical calculation and statistical mapping[^1]. In addition, R is often used in bioinformatics analysis .
RStudio : RStudio is an integrated development environment for R. The interface is richer and more practical, and it is more convenient to use.
RStudio Server : RStudio Server is the web version of RStudio. It is more flexible. After being deployed on a remote server, you can complete the work of R language on the local computer through a browser anytime and anywhere .

2. Install R on Ubuntu 20.04

  • R official website https://www.r-project.org/

  • Click download R to enter the download interface

  • Select the source mirror in Ubuntu, I chose the drop-down -> the source mirror China of University of Science and Technology of China https://mirrors.ustc.edu.cn/CRAN/ (there is a method for Ubuntu to change the source mirror in the later steps)

  • Select Download R for Linux (Ubuntu)

  • I don’t quite understand this page, but see the full README on the page seems to introduce slightly different methods of downloading R for different Ubuntu versions, and my server is Ubuntu 20.04, so I need to choose Focal Fossa . Next, R will be installed in several steps

  • Add the GPG key (I don’t know much about the GPG key, but it’s no problem to run it directly according to the code given by the relevant blog on the Internet, and you must carefully understand the content later)
    -sudo apt-key adv --keyserver keyserver.ubuntu.com --recv-keys E298A3A825C0D65DFD57CBB651716619E084DAB9

  • According to the introduction in see the full README , you need to add a statement in /etc/apt/sources.listthe path file, because the server is Ubuntu 20.04, so the page has already indicated the statement to select the Focal Fossadeb https://cloud.r-project.org/bin/linux/ubuntu focal-cran40/ type . There are many related blogs and materials on the Internet to open the file and add There are two methods of statement, listed below (I used the first one), just choose one to add:
    Method 1:
    Manually open the source.list file to add (I use the source of University of Science and Technology of China)

    • sudo vi /etc/apt/sources.list(Manually open the source.list file)
    • Manually add at the end of the file: deb https://mirrors.ustc.edu.cn/CRAN/bin/linux/ubuntu focal-cran40/, and then Esc :wqsave

    Method 2:
    Run the script to automatically replace the mirror source in the source.list file and automatically add statements in the file (I use the source of the University of Science and Technology of China)

    • sodu sed -i 's/\/\/.*\/ubuntu/\/\/mirrors.ustc.edu.cn\/ubuntu/g' /etc/apt/sources.list(change mirror source)
    • sudo add-apt-repository 'deb https://cloud.r-project.org/bin/linux/ubuntu focal-cran40/(The official statement is automatically added here. I haven’t tried it and learned more. It should be possible.)
       
  • After changing the source and adding the statement, run the script sudo apt-get updateto update the source.list file once

  • Then run two installation scripts:
    - sudo apt-get install r-base
    -sudo apt-get install r-base

  • The installation is successful, just enter Rthe test to get the following interface:
    insert image description here
    summary, GPG key -> source.list file to add source and corresponding statement -> sudo apt-get update to update -> execute the installation script

3. Install RStudio (Desktop) on Ubuntu 20.04

  • On the basis of the successful installation of R, installing RStudio will be much simpler. This part is about RStudio (Desktop), which is the desktop version of RStudio (different from Server). First, RStudio official website download interface https://www.rstudio.com/products/rstudio/download/
  • You can choose the free version (Free) RStudio Desktop: https://www.rstudio.com/products/rstudio/download/#download
  • Select the installation file supported by Ubuntu 20.04 version to download, and save the downloaded deb format file in a certain path of Ubuntu
    insert image description here
  • Execute the installation script in the terminal to enter the deb format file path:
    • sudo apt-get install gdebi-core(seems to be an installation tool for installing deb files)
    • sudo gdebi -n rstudio-2022.02.1-461-amd64.deb(corresponding to the deb file just downloaded)

Note, if there is no graphical operation interface installed in the server, it seems that the downloaded RStudio Desktop cannot be opened, so you can install the following RStudio Server, and access the RStudio Server in the Ubuntu server through the browser on the local computer to perform various operation experiments

4. Install RStudio Server on Ubuntu 20.04

  • On the basis of the above, installing RStudio Server will be much simpler. This part is about RStudio Server. Similarly, in the download interface https://www.rstudio.com/products/rstudio/download/#download , I chose the free version (Free)
    insert image description here

  • Select the version supported by the Debian/Ubuntu system: https://www.rstudio.com/products/rstudio/download-server/debian-ubuntu/

  • The specific installation command is given on the official website page, just execute it directly:

    • sudo apt-get install gdebi-core(installed can be ignored)
    • wget https://download2.rstudio.org/server/bionic/amd64/rstudio-server-2022.02.1-461-amd64.deb(Deb file of the Server version downloaded through the network)
    • sudo gdebi rstudio-server-2022.02.1-461-amd64.deb(Execute the install command)
  • After the successful installation of the Server version, it can be accessed through the browser of the local computer:

    • Open the browser and enter in the address bar: http://你的Ubuntu服务器ip:8787(8787 is the default listening port of Rstudio Server, you can configure it yourself)
    • After opening normally, you need to enter the username and password, which is the username and password of the Ubuntu server
  • The browser enters the interface and displays (after entering, the experimental operation is the same as the Desktop version):
    insert image description here

Guess you like

Origin blog.csdn.net/zxk_75/article/details/123886402