学习生信,最好的环境应该是linux跑数据+网页端RStudio写代码。最好有随时可以访问的一台linux服务器。 没有的话,开启win10的linux子系统也是一个不错的选择。
下面开始配置环境。
1. 安装R
- 非常不推荐手动下载deb或者编译源码的方式安装R,因为依赖太多了,不好解决
- 首先要清楚自己的Linux版本:
lsb_release -a
Distributor ID: Ubuntu
Description: Ubuntu 18.04.2 LTS
Release: 18.04
Codename: bionic
然后找到ubuntu 18.04 (bionic)对应的R版本,查看网址:https://wiki.ubuntu.com/Releases
可以看到对应的R版本是
bionic
知道了R版本后,开始安装R:
- 首先添加 GPG key:由于R的更新速度非常快,ubuntu repository软件源列表中不一定有最新的版本,我们首先添加CRAN 的trested key:
sudo apt-key adv --keyserver keyserver.ubuntu.com --recv-keys E298A3A825C0D65DFD57CBB651716619E084DAB9
应该能够看到以下输出:
Output
Executing: /tmp/apt-key-gpghome.4BZzh1TALq/gpg.1.sh --keyserver keyserver.ubuntu.com --recv-keys E298A3A825C0D65DFD57CBB651716619E084DAB9
gpg: key 51716619E084DAB9: public key "Michael Rutter " imported
gpg: Total number processed: 1
gpg: imported: 1
注意,在WSL上安装时有可能会出现以下错误:
Executing: /tmp/apt-key-gpghome.BG01sRSmD5/gpg.1.sh --keyserver hkp://keyserver.ubuntu.com:80 --recv-keys 3FA7E0328081BFF6A14DA29AA6A19B38D3D831EF
gpg: connecting dirmngr at '/tmp/apt-key-gpghome.BG01sRSmD5/S.dirmngr' failed: IPC connect call failed
gpg: keyserver receive failed: No dirmng
解决办法:
sudo apt update
会出现以下错误:NO_PUBKEY 5523BAEEB01FA116
curl -sL "http://keyserver.ubuntu.com/pks/lookup?op=get&search=0x5523BAEEB01FA116" | sudo apt-key add
- key 添加完毕后,就能添加软件源了,结合前面确定的R 版本:
sudo add-apt-repository 'deb https://cloud.r-project.org/bin/linux/ubuntu bionic-cran35/'
看到以下输出即成功:
Get:5 https://cloud.r-project.org/bin/linux/ubuntu bionic-cran35/ InRelease [3625 B]
...
Get:8 https://cloud.r-project.org/bin/linux/ubuntu bionic-cran35/ Packages [52.8 kB]
打开/etc/apt/sources.list
,可以看到添加的源
deb [arch=amd64] https://download.docker.com/linux/ubuntu bionic stable
# deb-src https://cloud.r-project.org/bin/linux/ubuntu xenial-cran35/
deb https://cloud.r-project.org/bin/linux/ubuntu bionic-cran35/
- 执行
sudo apt update
:
7 https://cloud.r-project.org/bin/linux/ubuntu bionic-cran35/ InRelease
#cran35: 虽然目前R已经到了3.6.x版本,但是为了向下兼容,命名依然采用35字样
- 安装rbase
sudo apt-get install r-base
, 若无问题即安装成功。
libopenblas-base
You should install R with OpenBLAS. In plain terms, OpenBLAS will boost some operations and I want you to be a happy user. You can ignore this advice if you are going to work with relatively small datasets.
在处理大数据集时,OpenBLAS可以帮助加快速度
sudo apt-get install libopenblas-base
- 运行R:
sudo -i R
Output
R version 3.5.1 (2018-07-02) -- "Feather Spray"
Copyright (C) 2018 The R Foundation for Statistical Computing
Platform: x86_64-pc-linux-gnu (64-bit)
...
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.
>
- 安装完毕后查看R版本:
R --version
若安装过程中有任何疑问,可以参考这篇文章:https://rtask.thinkr.fr/blog/installation-of-r-3-5-on-ubuntu-18-04-lts-and-tips-for-spatial-packages/
安装过程中出现以下问题, 或者版本过低 的解决办法:
The following packages have unmet dependencies:
r-base : Depends: r-recommended (= 3.5.0-1bionic) but it is not going to be installed
E: Unable to correct problems, you have held broken packages.
remove the source
deb https://cloud.r-project.org/bin/linux/ubuntu bionic-cran35/
from Software sources.Basic cleanup :-
sudo apt-get autoremove
sudo apt-get update
sudo apt-get upgrade
Install whatever existing version in Ubuntu Bionic with
sudo apt-get install r-base
Re-add the source deb https://cloud.r-project.org/bin/linux/ubuntu bionic-cran35/
sudo apt-get update
sudo apt-get upgrade
; Upgrade all the existing packages in Linuxsudo apt-get dist-upgrade
最后一步将升级R到最新版本
2. 安装RStudio Server版,
https://www.rstudio.com/products/rstudio/download-server/
sudo apt-get install gdebi-core
wget https://download2.rstudio.org/server/trusty/amd64/rstudio-server-1.2.1335-amd64.deb
sudo gdebi rstudio-server-1.2.1335-amd64.deb
安装完毕后服务自动开启在8787端口,如果暴露给外网还要打开防火墙端口,建议使用ufw
管理防火墙。
我们还需要在系统中添加一个用户,用来访问RStudio:
sudo adduser youname
添加完成后,浏览器打开ip:8787就能访问了:
指定RStudio使用R
将以下添加到~/.profile
:
# export RSTUDIO_WHICH_R=/path/to/your/R # this is what RStudio usually uses
export RSTUDIO_WHICH_R=/usr/local/bin/R # R的安装位置
. ~/.profile # reloads the profile without requiring us to logout+login again
3. 安装gdc-client
到这里下载最新版gdc-client
wget https://gdc.cancer.gov/system/files/authenticated%20user/0/gdc-client_v1.4.0_Ubuntu_x64.zip
unzip gdc-client_v1.4.0_Ubuntu_x64.zip
我们将得到gdc-client可执行文件,位于当前目录下,为了方便使用,我们还需要将其加入环境变量:
打开~/.bashrc
#通过修改.bashrc文件:
vim ~/.bashrc
#在最后一行添上:
export PATH=you gdc-client path:$PATH
#生效方法:(有以下两种)
#1、关闭当前终端窗口,重新打开一个新终端窗口就能生效
#2、输入“source ~/.bashrc”命令,立即生效
#有效期限:永久有效
#用户局限:仅对当前用户
4. 其它
推荐使用xshell免费版与服务器进行ssh连接,虽然RStudio也自带终端,但xshell的上传下载命令lrzsz
实在是太好用了(我们有时需要在win上下载manifeste文件,上传到linux进行数据下载),https://blog.csdn.net/liuruiqun/article/details/45921921
下载数据中
image.png
这样我们无论何时下载好的数据都在服务端,我们可以随时随地开始分析