# Having a nice setup of Spatial Data Science in Ubunutu/debian **Goals**: setting a nice Linux ubuntu/debian setup for Spatial data science! - Bonus points if it can be reproducible! - It can be used remote from a crappy laptop - We will learn something about Open Sources, Linux, R and more! :::info **Disclaimer:** Feel free to improve it! I am bad at everything but I like to learn and I am stubborn! ::: :::success **Reminder:** I am not familiar with this kind of markdown but I wanna try fancy stuff or just discover it: https://hackmd.io/features?both ::: ## Ressources ### Full set-up: - [Arch Linux setup guide tailored towards data science, R and spatial analysis](https://pat-s.me/arch-install-guide-for-r/) from Patrick Schratz ([@patscli](https://twitter.com/patscli?s=20&t=zuzKkZOMvFuCsFknGVDd2Q)), very nice blog starting point of this text. If only we could setup this kind of environement in ubuntu! - [Installation of R 4.0 on Ubuntu 20.04 LTS and tips for spatial packages](https://rtask.thinkr.fr/installation-of-r-4-0-on-ubuntu-20-04-lts-and-tips-for-spatial-packages/) from Sébastien Rochette ([@StatnMap](https://twitter.com/StatnMap?s=20&t=x6tbjzTuC-zQ1L1EiNCZiQ)) - [Installing spatial R packages on Ubuntu](https://geocompr.github.io/post/2020/installing-r-spatial-ubuntu/) from Robin Lovelace ([@robinlovelace](https://twitter.com/robinlovelace?s=20&t=x6tbjzTuC-zQ1L1EiNCZiQ)) ### R and Linux - [Debian Packages of R Software](https://cran.rstudio.com/bin/linux/debian/) - [Ubuntu Packages For R - Full Instructions](https://cran.r-project.org/bin/linux/ubuntu/fullREADME.html) ### Rstudio - [Download RStudio Server for Debian & Ubuntu](https://www.rstudio.com/products/rstudio/download-server/debian-ubuntu/) from Rstudio ([@rstudio](https://twitter.com/rstudio?s=20&t=x6tbjzTuC-zQ1L1EiNCZiQ)) ### Tips and tricks - [(Much) Faster Package (Re-)Installation via Caching ](https://dirk.eddelbuettel.com/blog/2017/11/27/#011_faster_package_installation_one) fomr Dirk Eddlbluettel ([@eddelbuettel](https://twitter.com/eddelbuettel?s=20&t=zuzKkZOMvFuCsFknGVDd2Q)). I have failed to install `ccache` but I definitelty feel this could be important (advice welcome!) - [Speeding up package installation](https://www.jumpingrivers.com/blog/speeding-up-package-installation/) from Colin Gillespie ([@jumping_uk](https://twitter.com/jumping_uk?s=20&t=zuzKkZOMvFuCsFknGVDd2Q)) ## Before R ### Protecting the server (a bit) #### New user and Root I probably do not do enough (if you have a nice learning material freel free to add it)! But this is what I do. You should first log into the server with ssh and create a pair of keys (both side need openssh) Then I change the pwd of root for my usual one (the same of my briefcase) : `1234` ``` bash= sudo passwd root # 1234 # 1234 ``` In `/etc/ssh/sshd_config` I turn `PermitRootlogin no` or add it. Lot of smarter and knowledgeable people also change the port, I do not do it mostly for huge laziness. This is also time to create a new user with sudo right. ``` bash= sudo adduser bob sudo adduser bob sudo ``` Ubuntu will create on 1 a nice `/home/bob` and asks you few questions and 2 add bob to sudo group. ``` bash= su - bob sudo userdel -r ubuntu ``` -r is used to remove some user related files. Now the next stuff is to do the updates! #### nftables This is here you need to ask an expert! #### Update! ``` sudo apt-get update sudo apt-get upgrade ``` ### Basic stuff really needed: Already in ubuntu but not in debian: - cURL - Git - ssh - for website apache2 is needed and need to be [installed](https://ubuntu.com/server/docs/web-servers-apache) ### Repositories You kind of have always two options: - The blue pill 🔵: you use some already build packages from repositories - The red pill 🔴: you build from source I prefer the blue pill because I have a very bad understanding of cmake! (but sometimes you do not have choice) You will need repositories where you can access them (and that means people behind the screens that do this works) A very basic debian have this repositories (inside `/etc/apt/sources.list`): ``` bash= deb http://deb.debian.org/debian/ buster main contrib non-free deb http://security.debian.org/debian-security buster/updates main contrib non-free ``` and this is what I have now in Ubunutu: ``` bash= ## Note, this file is written by cloud-init on first boot of an instance ## modifications made here will not survive a re-bundle. ## if you wish to make changes you can: ## a.) add 'apt_preserve_sources_list: true' to /etc/cloud/cloud.cfg ## or do the same in user-data ## b.) add sources in /etc/apt/sources.list.d ## c.) make changes to template file /etc/cloud/templates/sources.list.tmpl # See http://help.ubuntu.com/community/UpgradeNotes for how to upgrade to # newer versions of the distribution. deb http://nova.clouds.archive.ubuntu.com/ubuntu/ focal main restricted # deb-src http://nova.clouds.archive.ubuntu.com/ubuntu/ focal main restricted ## Major bug fix updates produced after the final release of the ## distribution. deb http://nova.clouds.archive.ubuntu.com/ubuntu/ focal-updates main restricted # deb-src http://nova.clouds.archive.ubuntu.com/ubuntu/ focal-updates main restricted ## N.B. software from this repository is ENTIRELY UNSUPPORTED by the Ubuntu ## team. Also, please note that software in universe WILL NOT receive any ## review or updates from the Ubuntu security team. deb http://nova.clouds.archive.ubuntu.com/ubuntu/ focal universe # deb-src http://nova.clouds.archive.ubuntu.com/ubuntu/ focal universe deb http://nova.clouds.archive.ubuntu.com/ubuntu/ focal-updates universe # deb-src http://nova.clouds.archive.ubuntu.com/ubuntu/ focal-updates universe ## N.B. software from this repository is ENTIRELY UNSUPPORTED by the Ubuntu ## team, and may not be under a free licence. Please satisfy yourself as to ## your rights to use the software. Also, please note that software in ## multiverse WILL NOT receive any review or updates from the Ubuntu ## security team. deb http://nova.clouds.archive.ubuntu.com/ubuntu/ focal multiverse # deb-src http://nova.clouds.archive.ubuntu.com/ubuntu/ focal multiverse deb http://nova.clouds.archive.ubuntu.com/ubuntu/ focal-updates multiverse # deb-src http://nova.clouds.archive.ubuntu.com/ubuntu/ focal-updates multiverse ## N.B. software from this repository may not have been tested as ## extensively as that contained in the main release, although it includes ## newer versions of some applications which may provide useful features. ## Also, please note that software in backports WILL NOT receive any review ## or updates from the Ubuntu security team. deb http://nova.clouds.archive.ubuntu.com/ubuntu/ focal-backports main restricted universe multiverse # deb-src http://nova.clouds.archive.ubuntu.com/ubuntu/ focal-backports main restricted universe multiverse ## Uncomment the following two lines to add software from Canonical's ## 'partner' repository. ## This software is not part of Ubuntu, but is offered by Canonical and the ## respective vendors as a service to Ubuntu users. # deb http://archive.canonical.com/ubuntu focal partner # deb-src http://archive.canonical.com/ubuntu focal partner ``` More need to be added, at least you need the R-project one: ``` bash= deb http://cloud.r-project.org/bin/linux/debian buster-cran40/ ``` :::info To add a repository to /etc/apt/sources.list you need at least sudo right. You can use nano or vim to add it. Nano is easier. ::: Managing package can be hard R can profide sone [help](https://hackmd.io/SfYUeElZRBaFWFkS25Pzqg?both#pak)! ### Packages and what they do | Package | What it does | Link | | -------- | -------- | -------- | | libudunits2-dev | units of physical quantities and a unit-definition and value-conversion utility | [website](https://www.unidata.ucar.edu/software/udunits/udunits-2.0.4/udunits2.html) | ### Nice to have - Docker ### A nice terminal I am using one and I do think it is worth it but it come with a bit of "overheat". Bash is still a perfectly fine terminal (and easier!) if you do not bother! I like the autocompletion and nice colors: > Strangers will come up to you in cafés and ask you, "that is amazing! are you some sort of genius?" I know two of them: - [Oh my ZSH!](https://ohmyz.sh/) - [Prezto](Prezto) I use the first one but mostly because I discovered it first. To install it you need: - install zsh - then curl or wget the github repo (see [here](https://github.com/ohmyzsh/ohmyzsh/wiki)) I do not have the total workflow on how zsh pick on bash and how oh-my-zsh pick on zsh (my bad! 😞) but what is important is aliasing! (yes you are using CLI to save time and alias are part of that). If you are not sold keep in mind that the terminal you are using in Rstudio will also become Oh my ZSH (yes this is cool)! But you can find how to do that [here](https://stephencharlesweiss.com/oh-my-zsh-and-persistent-aliases#adding-an-alias-the-easy-way) thanks to Stephen Charlesweiss. I will provide a quick example with radian next! Btw I have not spend time picking the better looking themes but feel free to experiment! I liked that the basic one as a lot of git alias so stay with it! ![](https://i.imgur.com/quegSFl.png) Imagine we can set up a nice config for spatial data science with it! ## R and more I wanted to try openblas so we install it: ``` bash= sudo apt-get install libopenblas-dev ``` First we need R ``` bash= sudo apt install r-base r-base-core r-recommended r-base-dev ``` ### Radian Radian is a : > radian is an alternative console for the R program with multiline editing and rich syntax highlight. And is quite nice! you can learn more about it and star it [here](https://github.com/randy3k/radian). you need to have a recent Python 3 and need pip: ``` bash= sudo apt install python3-pip pip3 install -U radian ``` You can now call R (normal R) or radian with `radian` It is easier to alias it with `r` : ``` bash= sudo nano ~/.oh-my-zsh/custom/example.zsh ``` Then add `alias r="radian"` and save it. R is used also for `R CMD` so keep it! ![](https://i.imgur.com/pMvzjwC.png) ### Rstudio server Following instructionand it works!:tada: You will probably need to open the port from your firewall, in ubuntu this is done by `ufw` By default it look like Rstudio use the same group/user and pwd from your OS. could be a good idea to change it and also do a more secure connection. ### Cran Task View or geocompr/geocompkg ### Other cool packages trivia - optipng #### pak link: https://pak.r-lib.org/ #### r2u https://eddelbuettel.github.io/r2u/