Skip to content

Commit

Permalink
Now using nvm (Node Version Manager) on linux, install node locally (…
Browse files Browse the repository at this point in the history
…no sudo)

- update linux instructions for ubuntu 20.04:
the old install method from node.js's github does not work anymore,
using nvm (Node Version Manager) node.js install method now, which
supports many node versions and allows to easily backwards use
an old node version for testing or compatibility reasons.

- install node locally (no sudo):
now installing gtp2ogs locally in home folder (instead of global
install).
this provides a lot of advantages, including no need to use `sudo`
anymore (since we can modify locally our gtp2ogs folder in
~/gtp2ogs-node/node_modules/gtp2ogs, and most importantly for
developers we can use `git` to easily checkout between branches
and test changes very easily

note: did not update the last 2 part's screenshots due to a lack of
time to set up another AI, as PhoenixGo is currently not yet supported
in Ubuntu 20.04. Todo in the upcoming future.

- greatly polished old linux instructions.
  • Loading branch information
wonderingabout committed May 8, 2020
1 parent 3db7a85 commit 2b9bfd0
Show file tree
Hide file tree
Showing 18 changed files with 199 additions and 211 deletions.
4 changes: 3 additions & 1 deletion docs/3A0-FOR-LINUX.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,11 @@
- [3B5) Run gtp2ogs.js (beta)](/docs/3B5-windows-run-gtp2ogs-js-beta.md)
- [3B6) Run gtp2ogs.js (official)](/docs/3B6-windows-run-gtp2ogs-js-beta.md)

# 3A0) FOR LINUX

So :

- Nodejs is a javascript server tool that we will use to run gtp2ogs later
- node.js is a javascript server tool that we will use to run gtp2ogs later
- gtp2ogs is a javascript program used to communicate in both directions
(in and out) in GTP language between your AI bot engine (example : PhoenixGo,
leela zero, etc..) and the OGS distant board where the game is played
Expand Down
85 changes: 66 additions & 19 deletions docs/3A1-linux-download-install-nodejs.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,35 +25,82 @@
- [3B5) Run gtp2ogs.js (beta)](/docs/3B5-windows-run-gtp2ogs-js-beta.md)
- [3B6) Run gtp2ogs.js (official)](/docs/3B6-windows-run-gtp2ogs-js-beta.md)

3A1) Download and install nodejs and npm
# 3A1) Download and install nodejs and npm

To install nodejs, I’ll go for the easy way and use package manager
(apt-get for ubuntu) with ppa, feel free to use another method if you
want, but this one is easy and works :
This tutorial uses Ubuntu 20.04 as an example, but it works the same in any
compatible linux distribution.

Package is provided
[from here](https://github.com/nodesource/distributions/blob/master/README.md#installation-instructions)
# Install node and npm

I’m using ubuntu 16.04 as an example for this tutorial.
To install node.js, apt package manager only provides an old version
of nodejs, so the recommended way to install node.js for ubuntu 20.04
and higher is to use `nvm` (Node Version Manager).

I also prefer to use the LTS version 10 (more stable, less issues),

Download and install nodejs and npm, then check if nodejs and npm
were successfully installed with the `-v` and `which` commands:
First, download and install the latest version of `nvm`
by downloading and runnning `install.sh` [from nvm's github](https://github.com/nvm-sh/nvm#installing-and-updating)

```
curl -sL https://deb.nodesource.com/setup_10.x | sudo -E bash - && sudo apt-get install -y nodejs && nodejs -v && npm -v && which nodejs && which npm
For example, as of today:

```Shell
curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.33.8/install.sh | bash
```

After install is a success, result is something like this :
Then finalize the install by updating your shell environment

```Shell
source ~/.profile
```
v10.14.2
6.4.1
/usr/bin/nodejs
/usr/bin/npm
```

![node81](https://github.com/wonderingabout/gtp2ogs-tutorial/blob/master/pictures/node81.png?raw=true)
You can check nvm is installed by running `nvm -v`.

Then, display all available node versions that can be installed by running
`nvm ls-remote`

![nvm install 0](/pictures/nvm-install-0.png)

In this tutorial i'll be choosing node version 14 because it is the soon to
be LTS at the time of writing this tutorial, and it adds support for a recent
addition to the javascript language that i want ([nullish coalescing](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Nullish_coalescing_operator))

Generally, unless there is a specific need, it is advised to go either with latest LTS
or latest beta version available depending on your needs. You can also check node.js
releases status [here](https://nodejs.org/en/about/releases/).

So, scrolling all available versions result all the way down until the bottom...

In this example, i'm running `nvm install 14.2.0` (latest node 14 available)

![nvm install 1](/pictures/nvm-install-1.png)

Finally, we can make sure `node` and `npm` were successfully installed by running `node -v` and `npm -v`.

# How to change node and npm version

You may want to upgrade to a more recent node version, or go do the opposite and test an older version for compatibility or debugging purposes.

To do that, just do `nvm install <version_number>` to install (if not already installed)
and switch to using the specified `<version_number>`

For example, to use node `14.0.0` instead of `14.2.0` i have to run `nvm install 14.0.0`

To revert it back, just do the opposite, for example `nvm install 14.2.0` to use
node version 14.2.0 again)

![nvm node upgrade 0](/pictures/nvm-node-upgrade-0.png)

# How to upgrade nvm

It is a good idea to upgrade `nvm` to latest available version whenever you want to use it (modify node version for example, as seen above)

For example, at the time i am updating this tutorial, `nvm` latest version is not anymore `0.33.8`
but is now `0.35.2`

To do that, just run the nvm install again as we saw at the begining:

- install latest `install.sh` from nvm's github
- update shell environment with `source ~/.profile`

![nvm upgrade 0](/pictures/nvm-upgrade-0.png)

[Next page ->](/docs/3A2-linux-install-gt2ogs-js-with-npm.md)
28 changes: 10 additions & 18 deletions docs/3A2-linux-install-gt2ogs-js-with-npm.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,32 +25,24 @@
- [3B5) Run gtp2ogs.js (beta)](/docs/3B5-windows-run-gtp2ogs-js-beta.md)
- [3B6) Run gtp2ogs.js (official)](/docs/3B6-windows-run-gtp2ogs-js-beta.md)

3A2) Install gtp2ogs.js with npm
# 3A2) Install gtp2ogs.js with npm

Run :
We need to choose a folder where we install gtp2ogs, for example `~/gtp2ogs-node`

```
sudo npm install -g gtp2ogs
```
Then, go inside this folder with `cd gtp2ogs-node`.

Result is something like this :
Then in that folder, run:

```Shell
npm install gtp2ogs
```
/usr/bin/gtp2ogs -> /usr/lib/node_modules/gtp2ogs/gtp2ogs.js
+ [email protected]
added 88 packages from 54 contributors in 5.734s
```

The path that is highlighted **/usr/lib/node_modules/gtp2ogs/** will
be important for later

Note : in some situations npm is installed in
/usr/local/lib/node_modules/gtp2ogs/gtp2ogs.js
gtp2ogs will be installed in that example in `~/gtp2ogs-node/node_modules/gtp2ogs`

![node81](https://github.com/wonderingabout/gtp2ogs-tutorial/blob/master/pictures/node81.png?raw=true)
![node l 001](/pictures/node-l-001.png)
![node l 002](/pictures/node-l-002.png)

If that’s the case for you, replace /usr/lib/ to /usr/local/lib
in all the steps you see below
[credits for the nvm install instructions for ubuntu 20.04 to linuxconfig.org](https://linuxconfig.org/how-to-install-node-js-on-ubuntu-20-04-lts-focal-fossa)

[Next page ->](/docs/3A3-linux-optional-upgrade-to-devel.md)

128 changes: 40 additions & 88 deletions docs/3A3-linux-optional-upgrade-to-devel.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,107 +25,59 @@
- [3B5) Run gtp2ogs.js (beta)](/docs/3B5-windows-run-gtp2ogs-js-beta.md)
- [3B6) Run gtp2ogs.js (official)](/docs/3B6-windows-run-gtp2ogs-js-beta.md)

3A3) Optional : Upgrade gtp2ogs from old branch to “devel” branch (latest)
# 3A3) Optional : Upgrade gtp2ogs from old branch to “devel” branch (latest)

**(This step is not an obligation, but it is highly recommended and only takes a few minutes)**
**This step is highly recommended**, even though you can skip it.

**UPDATE FEBRUARY 2019 : the old gtp2ogs.js has been split into many modules, to upgrade your gtp2ogs to devel, you now need to upgrade all the gtp2ogs files (gtp2ogs.js, bot.js, config.js, etc...). But the process to upgrade your branch is the same : just copy all gtp2ogs files now, instead of only gtp2ogs.js in the past**
The last stable release of gtp2ogs is old does not include recent fixes and improvements,
see [the official gtp2ogs devel branch's github](https://github.com/online-go/gtp2ogs/tree/devel)

note: as of february 2019, the old gtp2ogs.js has been split into many modules. To upgrade your
gtp2ogs version to devel, this is not relevant, because all we have to do is regardless just
to replace old gtp2ogs folder with the devel one.

The last stable release of gtp2ogs is old, it is higly recommended to use
the devel branch of gtp2ogs rather, to have latest fixes and improvements,
see [the official github](https://github.com/online-go/gtp2ogs/tree/devel)

Note : The generic command `sudo npm install -g --save online-go/gtp2ogs#devel --save`
should have allowed to do it, but it seems using the `#` is forbidden by
online-go github, so we will rather download gtp2ogs devel branch ZIP
archive directly.
# Upgrade to online-go/devel latest version

To upgrade gtp2ogs.js to devel branch, we’ll use the all in one command
below :

The all-in-one command below uses the path where gtp2ogs.js was installed
in node_modules, that we highlighted in red earlier.

In this example, it is : **/usr/lib/node_modules/gtp2ogs/gtp2ogs.js**
below:

(if your path is different, replace it in the command below and in all
the next steps of this tutorial)
note 2: if backup folder already exists, it will tell that to you, but
this doesnt prevent our all in one command from being executed
(backup folder content will just be overwritten)

Note : if backup folder already exists, it will tell that to you, but
this doesnt prevent
our all in one command from being executed (backup folder content will
just be overwritten)

```
```Shell
# Making backup of existing gtp2ogs && \
sudo mkdir ~/gtp2ogs-backup ; \
sudo cp -rf /usr/lib/node_modules/gtp2ogs/* ~/gtp2ogs-backup && \
# Overwriting existing gtp2ogs with newly cloned gtp2ogs branch && \
cd ~ && mkdir testtt && cd testtt && \
git clone -b devel https://github.com/online-go/gtp2ogs && cd gtp2ogs && \
git branch && ls && \
sudo cp -rf * /usr/lib/node_modules/gtp2ogs/ && \
# Post-install cleanup && \
sudo rm -rf ~/testtt && \
# Going to destination folder && \
cd /usr/lib/node_modules/gtp2ogs/ && \
# Installing extra needed packages from new branch's package.json && \
sudo npm install && \
sudo npm audit fix --force && \
mkdir ~/gtp2ogs-backup ; \
cd ~/gtp2ogs-node/node_modules/gtp2ogs && \
cp -rf * ~/gtp2ogs-backup/ && \
# Delete existing gtp2ogs folder && \
cd .. && \
rm -rf gtp2ogs && \
# Install gtp2ogs latest devel cloned from github && \
git clone -b devel https://github.com/online-go/gtp2ogs && \
cd gtp2ogs && \
git branch && \
# Installing locally extra needed dependencies from new branch's package.json && \
npm install && \
ls
```
![node l 003](https://github.com/wonderingabout/gtp2ogs-tutorial/blob/master/pictures/node-l-003.png?raw=true)

You can also use any custom branch that has some extra features or
fixes, for example using this branch instead of the online-go/gtp2ogs
official devel branch, in the same command line than above :
If you just want to use gtp2ogs easily (not dev), you can also copy paste
(from downloaded ZIP on github website) any other branch
that has some extra features or fixes, for example using this command
`git clone -b roy7live-textonly-phoenixgo https://github.com/wonderingabout/gtp2ogs && \`
in the same command line than above.

```
# Making backup of existing gtp2ogs && \
sudo mkdir ~/gtp2ogs-backup ; \
sudo cp -rf /usr/lib/node_modules/gtp2ogs/* ~/gtp2ogs-backup && \
# Overwriting existing gtp2ogs with newly cloned gtp2ogs branch && \
cd ~ && mkdir testtt && cd testtt && \
git clone -b roy7live-textonly-phoenixgo https://github.com/wonderingabout/gtp2ogs && cd gtp2ogs && \
git branch && ls && \
sudo cp -rf * /usr/lib/node_modules/gtp2ogs/ && \
# Post-install cleanup && \
sudo rm -rf ~/testtt && \
# Going to destination folder && \
cd /usr/lib/node_modules/gtp2ogs/ && \
# Installing extra needed packages from new branch's package.json && \
sudo npm install && \
sudo npm audit fix --force && \
ls
```
# For developers

If you're a developper, you'd most likely want to use your own repository, so you'd run
the same command as above, except that you'd use devel or any other branch from YOUR repository
(i am `wonderingabout` for example `git clone -b devel https://github.com/wonderingabout/gtp2ogs && \`)

![node l 004](https://github.com/wonderingabout/gtp2ogs-tutorial/blob/master/pictures/node-l-004.png?raw=true)

Note : do not mind the other files and folders in this screenshot,
they are not needed for this tutorial

Note 2 : do not mind the warning permission denied, it doesn't
prevent us from doing what we want

![node82](https://github.com/wonderingabout/gtp2ogs-tutorial/blob/master/pictures/node82.png?raw=true)

Explanation of what this command does :

- in node_modules install path of gtp2ogs files (in this example
/usr/lib/node_modules/gtp2ogs/), do a backup of all the gtp2ogs files
in a new folder called "gtp2ogs-backup" in home folder (we can revert
to that later if we want),
- then go to home folder,
- create a folder named “testtt”,
- go into that testtt folder,
- clone gtp2ogs devel (it is the latest) branch from github,
- go into that github gtp2ogs devel folder,
- check branch which is selected (should be devel),
- show a list of the files,
- then copy all gtp2ogs files in that devel folder recursively into
the node_modules gtp2ogs path folder /usr/lib/node_modules/gtp2ogs/ ,
(will erase old files, but we created a backup of gt2ogs files earlier
so no problem here)
- then cleanup by removing the testtt folder in home folder we used,
- and finally go back to where gtp2ogs files were installed as explained
earlier (in this example /usr/lib/node_modules/gtp2ogs/ )
This method installs gtp2ogs locally in your home folder, which allows to easily change branches
with `git checkout` and do any other dev operation very conveniently!

[Next page ->](3A4-linux-optional-edit-gtp2ogs-js-file.md)
Loading

0 comments on commit 2b9bfd0

Please sign in to comment.