Site icon R-bloggers

[R] install and configure Rstudio-server in ubuntu

[This article was first published on R on Zhenguo Zhang's Blog, and kindly contributed to R-bloggers]. (You can report issue about the content on this page here)
Want to share your content on R-bloggers? click here if you have a blog, or here if you don't.
Zhenguo Zhang’s Blog /2023/05/28/r-install-and-configure-rstudio-server-in-ubuntu/ –

Rstudio server provides an integrative environment for a data scientist to do data analysis in R and python and allows one to login into it via a browser anywhere. Today, I will going to show how to install Rstudio server in Ubuntu under AWS.

Setup EC2 instance

To access Rstudio server in an EC2 instance, one need to open correct port in the security group and set the Source to “Anywhere” (i.e., 0.0.0.0). The needed ports are as follows:

Install R

The next step is to install R in the EC2 instance after ssh to it. Use the following command to install the R

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
# update indices
sudo apt update -qq
# install two helper packages we need
sudo apt install --no-install-recommends software-properties-common dirmngr
# add the signing key (by Michael Rutter) for these repos
# To verify key, run gpg --show-keys /etc/apt/trusted.gpg.d/cran_ubuntu_key.asc 
# Fingerprint: E298A3A825C0D65DFD57CBB651716619E084DAB9
wget -qO- https://cloud.r-project.org/bin/linux/ubuntu/marutter_pubkey.asc | sudo tee -a /etc/apt/trusted.gpg.d/cran_ubuntu_key.asc
# add the R 4.0 repo from CRAN -- adjust 'focal' to 'groovy' or 'bionic' as needed
sudo add-apt-repository "deb https://cloud.r-project.org/bin/linux/ubuntu $(lsb_release -cs)-cran40/"
sudo apt install --no-install-recommends -y r-base r-base-dev

The above commands are for installing version 4+ R. For other versions, refer to the documents at https://cran.r-project.org/bin/linux/ubuntu/.

Install Rstudio server

To install the latest version of Rstudio server, go to the page https://posit.co/download/rstudio-server/ and find the corresponding .deb package for the OS. Here is the example to install Rstudio server in Ubuntu 22.04.

1
2
3
sudo apt-get install gdebi-core
wget https://download2.rstudio.org/server/jammy/amd64/rstudio-server-2023.03.1-446-amd64.deb
sudo gdebi rstudio-server-2023.03.1-446-amd64.deb

If the command ‘gdebi’ does not work, one can use

1
sudo apt install rstudio-server-2023.03.1-446-amd64.deb

Configure Rstudio server

User management

To create/add a new user rstudio, use the following command

1
2
3
sudo adduser rstudio # this also create a new group rstudio if not exist
# add user rstudio to sudo group
sudo usermod -aG sudo rstudio # this will also prompt for password, which will be used for rstudio login

In default, all existing users with uid > 100 can login into the rstudio server, too. However, for EC2 users, they don’t have a password. To create one password, one need to run the following:

1
2
3
sudo passwd ubuntu # create new password for login to Rstudio server
# you can also add ubuntu to the group rstudio, run
sudo adduser ubuntu rstudio

Server setting

One can skip this step if he wants to test the server quickly, because these settings are for fine-tuning non-default values.

There are two configuration files:

For the server settings, open /etc/rstudio/rserver.conf, and the following parameters can be considered:

Important for the settings to take effect, one need to restart the server

For the rsession setting, one can open /etc/rstudio/rsession.conf and consider the following parameters:

Common Rstudio server commands

Start the server and login

Start the server

1
sudo rstudio-server restart

To connect, input http://your-ec2-ip-address:8787 in your browser (any client), you should see the login page, please input the username and password to login.

Hooray!!! Now you can use Rstudio anywhere.

Happy programming, 😄

Troubleshooting

References

– /2023/05/28/r-install-and-configure-rstudio-server-in-ubuntu/ –
To leave a comment for the author, please follow the link and comment on their blog: R on Zhenguo Zhang's Blog.

R-bloggers.com offers daily e-mail updates about R news and tutorials about learning R and many other topics. Click here if you're looking to post or find an R/data-science job.
Want to share your content on R-bloggers? click here if you have a blog, or here if you don't.
Exit mobile version