本操作需要root權(quán)限
2023-6-14更新
需要添加的R路徑變量有兩個(gè),建議用conda安裝的R,我用R安不上Seurat,換成用conda安就成功了
vi /etc/rstudio/rserver.conf
# Server Configuration File
rsession-ld-library-path=/path/to/anaconda3/envs/${R_VERSION}/lib/
rsession-which-r=/path/to/anaconda3/envs/${R_VERSION}/bin/R
然后還要鏈接一些東西到/usr/bin/
ln -s /path/to/anaconda3/envs/${R_VERSION}/bin/x86_64-conda* /usr/bin/
并重啟RStudio-Server
下載并安裝RStudio-Server
在RStudio官網(wǎng)選擇server免費(fèi)版

選server

選免費(fèi)版

選CentOS

兩行代碼搞定
wget https://download2.rstudio.org/server/centos7/x86_64/rstudio-server-rhel-2022.07.2-576-x86_64.rpm
sudo yum install rstudio-server-rhel-2022.07.2-576-x86_64.rpm
開啟8787端口并重啟RStudio-Server
systemctl enable rstudio-server.service
systemctl start rstudio-server.service
systemctl status rstudio-server
firewalld
firewall-cmd --permanent --add-port=8787/tcp
firewall-cmd --permanent --add-port=8787/udp
firewall-cmd --reload
rstudio-server restart
使用瀏覽器登錄
地址欄輸入IP:8787

輸入服務(wù)器賬號(hào)密碼(不要用root登錄)
修改R版本
CentOS7似乎不支持anaconda或者tar.gz格式的R
試了很多次各個(gè)版本都會(huì)導(dǎo)致不能啟動(dòng)server
然后發(fā)現(xiàn)官網(wǎng)其實(shí)有提示要下載rpm格式

點(diǎn)擊這個(gè)文件

不知道是什么東西但反正照做就是了
# Enable the Extra Packages for Enterprise Linux (EPEL) repository
sudo yum install https://dl.fedoraproject.org/pub/epel/epel-release-latest-7.noarch.rpm
# On RHEL 7, enable the Optional repository
sudo subscription-manager repos --enable "rhel-*-optional-rpms"
# If running RHEL 7 in a public cloud, such as Amazon EC2, enable the
# Optional repository from Red Hat Update Infrastructure (RHUI) instead
sudo yum install yum-utils
sudo yum-config-manager --enable "rhel-*-optional-rpms"

然后下載所需版本的rpm格式的R
export R_VERSION=4.2.1 #或者其他你需要的版本
curl -O https://cdn.rstudio.com/r/centos-7/pkgs/R-${R_VERSION}-1-1.x86_64.rpm
sudo yum install R-${R_VERSION}-1-1.x86_64.rpm
免費(fèi)版server并不支持多個(gè)R版本自由切換

tools-option-general沒有更改R版本選項(xiàng)
理論上說是可以更改配置文件解決的
vi /etc/rstudio/rserver.conf
然后添加R路徑變量
# Server Configuration File
rsession-which-r=/opt/R/${R_VERSION}/bin/R
并重啟RStudio-Server
rstudio-server restart
但實(shí)際上這樣會(huì)導(dǎo)致無法登錄,換成anaconda或者某人家目錄下R的路徑也行不通,最后的解決辦法是
sudo ln -s /opt/R/${R_VERSION}/bin/R /usr/bin/R #默認(rèn)路徑也可能是/usr/local/bin/R,都可以試試
sudo ln -s /opt/R/${R_VERSION}/bin/Rscript /usr/bin/Rscript
默認(rèn)路徑也可能是/usr/local/bin/R,都可以試試
然后重啟RStudio-Server就可以看到R版本切換成功
rstudio-server restart
早知道按官網(wǎng)來半小時(shí)就搞定了-_-|||
安好了還可以更改一下其他配置哦~