Installing Node.js from source on Arch Linux
#1
Information 
hi all,

so you may have run into some problems installing node.js from source with the arch linux image. 

yes, i am aware you can use Arch's pacman package manager to install node.js and npm, but those tend to name them nodejs on the command line, not the standard node and then you get into a whole other how-to on fixing that. i prefer my node compiled from source and ready to go the way i expect it.

so i thought i'd put together this how-to for those who may have run into similar difficulties.

the short, tl;dr

Arch Linux has python 3.5.1 installed (at least on the image we are using for Pine64 boards). make, node.gyp and the JavaScript V8 engine depend on python 2.7.x.

so do this —

install python2 to Arch Linux using —

Code:
pacman -S python2

from the command in your home directory do:

Code:
mkdir -p ~/bin/
ln -s $(which python2) ~/bin/python
export PATH=~/bin/:$PATH

...then, switch to the directory where you've downloaded and decompressed the node.js source and do —

Code:
cd /path/to/where/your/node.js-source-is/
./configure
make
sudo make install

voila! you got node! test it out with —

Code:
node -v
npm -v

...and — profit!  ? ? ? 

the long version

for background, check out this node.js issue on github, #2735, as well as the issue they all point to and reference, #418, as well as the issue i filed, #6249.
basically, it comes down to this — Arch Linux installs only Python v3.5.1, and the JavaScript V8 engine (maintained by Google's The Chromium Project), as well as Node.js' node.gyp and the script files for the build all want to use Python 2.7.x. If you go into script files for the node install like the configure file, you'll see that at top, it says —

Code:
#!/usr/bin/env python

now you could use Arch Linux's pacman (similar to deb repositories and apt in Ubuntu and rpm in RedHat) package installer to install Python 2.7.x change this to —

Quote:#!/usr/bin/env python2

...and that would work for a bit with the configure file, but would fail the moment anything is required of node.gyp or the V8 engine, as they have hard coded stuff in them for python which defaults to the OS' python default install, which in Arch Linux is Python 3.5.1.

so over that issue for node.js, @rvagg suggests the following — 
  • install Python 2.7.x to your Arch Linux install using the pacman package manager —
Code:
pacman -S python2
Code:
tar xvf node-vX.X.X-tar.xz

     this will create a node source install directory in your Downloads folder. you can go ahead and delete the compressed node.js source file now.
  • switch to your home directory
Code:
cd ~
  • run the following in the command line —
Code:
mkdir -p ~/bin/
ln -s $(which python2) ~/bin/python
export PATH=~/bin/:$PATH

     this creates a directory under your home directory that is "bin," you create a symbolic link from there to your python2 for installing, then you export that to your $PATH statement.
  • now switch back to the directory that has your node.js source install, and run the following —
Code:
cd /path/to/where/your/node.js-source-is/
./configure
make
sudo make install

     ... and voila, you got node!
  • now test it out using —
Code:
node -v
npm -v

     ...which should return, now, both the version numbers for node.js and npm.

...and — profit!  ? ? ? 

best,

—  faddah
     portland, oregon, u.s.a.
#2
(04-16-2016, 11:05 PM)faddah Wrote: hi all,

so you may have run into some problems installing node.js from source with the arch linux image. 

yes, i am aware you can use Arch's pacman package manager to install node.js and npm, but those tend to name them nodejs on the command line, not the standard node and then you get into a whole other how-to on fixing that. i prefer my node compiled from source and ready to go the way i expect it.

so i thought i'd put together this how-to for those who may have run into similar difficulties.

the short, tl;dr

Arch Linux has python 3.5.1 installed (at least on the image we are using for Pine64 boards). make, node.gyp and the JavaScript V8 engine depend on python 2.7.x.

so do this —

install python2 to Arch Linux using —

Code:
pacman -S python2

from the command in your home directory do:

Code:
mkdir -p ~/bin/
ln -s $(which python2) ~/bin/python
export PATH=~/bin/:$PATH

...then, switch to the directory where you've downloaded and decompressed the node.js source and do —

Code:
cd /path/to/where/your/node.js-source-is/
./configure
make
sudo make install

voila! you got node! test it out with —

Code:
node -v
npm -v

...and — profit!  ? ? ? 

the long version

for background, check out this node.js issue on github, #2735, as well as the issue they all point to and reference, #418, as well as the issue i filed, #6249.
basically, it comes down to this — Arch Linux installs only Python v3.5.1, and the JavaScript V8 engine (maintained by Google's The Chromium Project), as well as Node.js' node.gyp and the script files for the build all want to use Python 2.7.x. If you go into script files for the node install like the configure file, you'll see that at top, it says —

Code:
#!/usr/bin/env python

now you could use Arch Linux's pacman (similar to deb repositories and apt in Ubuntu and rpm in RedHat) package installer to install Python 2.7.x change this to —

Quote:#!/usr/bin/env python2

...and that would work for a bit with the configure file, but would fail the moment anything is required of node.gyp or the V8 engine, as they have hard coded stuff in them for python which defaults to the OS' python default install, which in Arch Linux is Python 3.5.1.

so over that issue for node.js, @rvagg suggests the following — 
  • install Python 2.7.x to your Arch Linux install using the pacman package manager —
Code:
pacman -S python2
Code:
tar xvf node-vX.X.X-tar.xz

     this will create a node source install directory in your Downloads folder. you can go ahead and delete the compressed node.js source file now.
  • switch to your home directory
Code:
cd ~
  • run the following in the command line —
Code:
mkdir -p ~/bin/
ln -s $(which python2) ~/bin/python
export PATH=~/bin/:$PATH

     this creates a directory under your home directory that is "bin," you create a symbolic link from there to your python2 for installing, then you export that to your $PATH statement.
  • now switch back to the directory that has your node.js source install, and run the following —
Code:
cd /path/to/where/your/node.js-source-is/
./configure
make
sudo make install

     ... and voila, you got node!
  • now test it out using —
Code:
node -v
npm -v

     ...which should return, now, both the version numbers for node.js and npm.

...and — profit!  ? ? ? 

best,

—  faddah
     portland, oregon, u.s.a.




This is on a unix system
To completely uninstall node + npm is to do the following:
  1. go to /usr/local/lib and delete any node and node_modules

  2. go to /usr/local/include and delete any node and node_modules directory

  3. if you installed with brew install node, then run brew uninstall node in your terminal

  4. check your Home directory for any local or lib or include folders, and delete any node or node_modules from there

  5. go to /usr/local/bin and delete any node executable
Then download nvm and follow the instructions to install node. The latest versions of node come with npm, I believe, but you can also reinstall that as well.


Possibly Related Threads…
Thread Author Replies Views Last Post
  linux-headers and quartz64-post-install package conflicts Berzerkleyfan 2 547 12-01-2023, 05:17 AM
Last Post: Berzerkleyfan
  Irradium (based on crux linux) riscv64, aarch64 mara 0 533 11-03-2023, 03:10 PM
Last Post: mara
Question Issue installing New OS Using SD Rudy558 2 3,564 06-29-2021, 03:37 AM
Last Post: TfromTexas
  Linux Headers jedichewbacca 5 8,487 02-28-2018, 10:35 PM
Last Post: evilbunny
  Mini-Tutorial to get a linux Desktop GUI working on Pine64+ speedro86 15 26,281 04-05-2017, 01:45 PM
Last Post: speedro86
  Arch Default Login, no luck. JzJad 1 4,062 02-01-2017, 10:27 PM
Last Post: tllim
  Linux laptop rusty377 2 4,238 11-27-2016, 08:52 PM
Last Post: pfeerick
  Install node.js on Ubuntu (via npm) Zhara 5 9,627 08-22-2016, 09:02 AM
Last Post: Zhara
  Installing remix os fooclueshoedo 3 5,141 07-07-2016, 06:33 PM
Last Post: fooclueshoedo
Bug ETA for solution for DMA problem for Arch Linux image & A64+ 2 GB boards? faddah 16 20,993 04-19-2016, 09:09 PM
Last Post: patrickhwood

Forum Jump:


Users browsing this thread: 1 Guest(s)