Installing node.js on raspberry pi 2 - node.js

I have installed Raspbian on my Raspberry Pi 2 and now I am trying to install node.js on it, however I am hitting an issue.
I followed the instructions and typed these commands into the terminal
wget http://node-arm.herokuapp.com/node_latest_armhf.deb
sudo dpkg -i node_latest_armhf.deb
But when I check the version of node using
node -v
I get this error:
node: /usr/lib/arm-linux-gnueabihf/libstdc++.so.6: version `GLIBCXX_3.4.20' not found (required by node)
node: /lib/arm-linus-gnueabihf/libc.so.6: version `GLIBC_2.16' not found (required by node)
I am quite new to using raspberry pi, so any help to fix this issue would be great!

Just putting the response from #Prashant Pathak above here:
Download latest nodejs build for Raspberry Pi:
wget https://nodejs.org/download/release/v0.10.0/node-v0.10.0-linux-arm-pi.tar.gz
Unpack files in local directory:
cd /usr/local
sudo tar xzvf ~/node-v0.10.0-linux-arm-pi.tar.gz --strip=1
That's it.
You can confirm it's there by checking the node version with:
node -v
and:
npm -v
The actual url to get the files for node will change as the version changes, you can always see the list of files available for download here:
http://nodejs.org/download/
All these instructions came from:
http://www.robert-drummond.com/2015/01/08/server-side-javascript-on-a-raspberry-pi-how-to-install-node-js-2/

Alternatively you can upgrade your GCC to V4.8 for this package to work!
Option 1 (the better option):
sudo apt-get update
sudo apt-get install gcc-4.8 g++-4.8
sudo update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-4.6 20
sudo update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-4.8 50
sudo update-alternatives --install /usr/bin/g++ g++ /usr/bin/g++-4.6 20
sudo update-alternatives --install /usr/bin/g++ g++ /usr/bin/g++-4.8 50
Options 2: Upgrade to Debian Jessie
Replace all instances of "wheezy" in /etc/apt/sources.list
sudo apt-get update
sudo apt-get dist-upgrade
After this you download the Node.js using command line as follows:
wget http://node-arm.herokuapp.com/node_latest_armhf.deb
Next step is to install the Node.js:
sudo dpkg -i node_latest_armhf.deb
Finally, you can verify the installation:
node -v
These instructions are mentioned on http://node-arm.herokuapp.com/

That runs for me:
http://blog.wia.io/installing-node-js-v4-0-0-on-a-raspberry-pi/
Raspberry Pi Model A, B, B+ and Compute Module
wget https://nodejs.org/dist/v4.0.0/node-v4.0.0-linux-armv6l.tar.gz
tar -xvf node-v4.0.0-linux-armv6l.tar.gz
cd node-v4.0.0-linux-armv6l
Raspberry Pi 2 Model B
wget https://nodejs.org/dist/v4.0.0/node-v4.0.0-linux-armv7l.tar.gz
tar -xvf node-v4.0.0-linux-armv7l.tar.gz
cd node-v4.0.0-linux-armv7l
sudo cp -R * /usr/local/

use nodejs instead of node
sudo apt-get update && sudo apt-get install nodejs
for npm
sudo apt-get install npm

The Latest Node is released for the below platforms, which helped for my old R-PI which is of model name : ARMv6-compatible processor rev 7 (v6l)
https://nodejs.org/download/release/v4.1.0/
node-v4.1.0-linux-arm64.tar.gz 17-Sep-2015 04:24 10886090
node-v4.1.0-linux-arm64.tar.xz 17-Sep-2015 04:24 7100824
node-v4.1.0-linux-armv6l.tar.gz 17-Sep-2015 17:37 10763504
node-v4.1.0-linux-armv6l.tar.xz 18-Sep-2015 00:15 7005048
node-v4.1.0-linux-armv7.tar.gz 17-Sep-2015 05:17 10773951
node-v4.1.0-linux-armv7.tar.xz 17-Sep-2015 05:18 7004760
node-v4.1.0-linux-armv7l.tar.gz 18-Sep-2015 12:58 10773951

You can try the following command:
wget node-arm.herokuapp.com/node_archive_armhf.deb
then
sudo dpkg -i node_archive_armhf.deb
node -v should work now!

Related

Installing .NET SDK on Ubuntu produces no executable dotnet file

Installing .NET SDK on Ubuntu 20.04 with the commands listed in the Install .NET on Ubuntu docs:
wget https://packages.microsoft.com/config/ubuntu/20.04/packages-microsoft-prod.deb -O packages-microsoft-prod.deb
sudo dpkg -i packages-microsoft-prod.deb
rm packages-microsoft-prod.deb
sudo apt-get update; \
sudo apt-get install -y apt-transport-https && \
sudo apt-get update && \
sudo apt-get install -y dotnet-sdk-6.0
produces no dotnet executable.
Command 'dotnet' not found, but can be installed with:
sudo snap install dotnet-sdk
Listing files from the package:
dpkg -L dotnet-sdk-6.0 | grep -P "dotnet$"
gives
/usr/share/dotnet
The /usr/share/dotnet directory contains no executable. I compared this result with my other Ubuntu installation where I installed dotnet ages ago, and there it is installed in /usr/share/dotnet but there exists a /usr/share/dotnet/dotnet executable.
What am I doing wrong? How to install dotnet on Ubuntu with APT?
Using snap is not an option.
sudo apt reinstall dotnet-host and then sudo apt install dotnet-sdk-6.0 fixed the issue.
See: https://github.com/dotnet/installer/issues/12939
dpkg -S /usr/bin/dotnet says that it was created by dotnet-host.
So maybe that package is missing in dotnet-sdk-6.0 and must be installed separately. I imagine they will fix it in some future version.
tl;dr $ sudo apt install dotnet-host

How to reinstall the latest cmake version?

I would like to install cmake the latest version, on Linux environment. I have cmake version 3.5 installed and is not supported by some applications. I tried to upgrade it by uninstalling the current version. But when I reinstall with sudo apt-get install cmake, I get the same version 3.5 re-installed. How do I install the latest version with sudo apt-get install ....?
As far as I know the best way to get the latest CMake version installed on any Linux is not by apt but using pip.
Remove the apt cmake and install the latest version from pip which can easily keep up-to-date.
apt remove cmake -y
pip install cmake --upgrade
Edit: As GNUton has pointed out, the following only works on Ubuntu 16.04 and 18.04(Checked on June 2019).
Now CMake developer team in Kitware Inc provides APT repositiory. It allows you to install latest CMake via apt-get.
If you are using a minimal Ubuntu image or a Docker image, you may need to install the following packages:
sudo apt-get update
sudo apt-get install apt-transport-https ca-certificates gnupg \
software-properties-common wget
Obtain a copy of our signing key:
wget -qO - https://apt.kitware.com/keys/kitware-archive-latest.asc |
sudo apt-key add -
Add the repository to your sources list and update.
For Ubuntu Bionic Beaver (18.04):
sudo apt-add-repository 'deb https://apt.kitware.com/ubuntu/ bionic main'
sudo apt-get update
For Ubuntu Xenial Xerus (16.04):
sudo apt-add-repository 'deb https://apt.kitware.com/ubuntu/ xenial main'
sudo apt-get update
... Optional steps. See details in reference.
... Optional steps. See details in reference.
Now call
sudo apt-get install cmake
Reference: Kitware APT Repository.
You can try the following steps that have worked for me on Ubuntu 18.04.3 LTS as OS of the NVIDIA jetson Nano to get the last version of cmake "cmake-3.14.0" from https://cmake.org/download/.
Delete the installed version in your system
sudo apt purge cmake
Download cmake3.13.4 source
wget https://github.com/Kitware/CMake/releases/download/v3.13.4/cmake-3.13.4.tar.gz
Extract files
tar zxvf cmake-3.13.4.tar.gz
Execute the following commands in this order to build it
cd cmake-3.13.4
sudo ./bootstrap
sudo make
sudo make install
Verify the version is installed correctly
cmake --version
Following the comments made on how to Install the latest CMake version and to post the answer for this question:
Ans:
This depends with Ubuntu OS version currently installed on your PC or Mac. If you have the following Ubuntu OS version then you have this CMake installed or that you could install and reinstall with "sudo apt-get install cmake". Even if you uninstall your version and try to reinstall later version.
Ubuntu 16.04 ships with cmake-3.5.1
Ubuntu 17.10 ships with cmake-3.9.1
Ubuntu 18.04 ships with cmake-3.10.2
Ubuntu 20.04 ships with cmake-3.16.3
Ubuntu 21.04 ships with cmake-3.18.4
Now if you have Ubuntu 16.04 installed and you want cmake-3.10, there is OS problem since you can only install and reinstalled cmake-3.5.1. To get cmake-3.10 or any other version, you have to download and install the package from https://packages.ubuntu.com/. Once you find the latest version of cmake .targz files, you have to build it yourself from the command line.
For CentOS/RHEL you can help these following steps:
yum -y install python-pip
pip install cmake --upgrade
If you are using Google Colab like me and wanted a higher version of cmake in it. Then do the following,
!pip uninstall cmake
!pip install cmake
This will install cmake 3.22 instead of the default version 3.12
pip install cmake --upgrade
if the following occurs after cmake .. :
CMake Error: Could not find CMAKE_ROOT !!!
CMake has most likely not been installed correctly.
Modules directory not found in
/.../.../...
CMake Error: Error executing cmake::LoadCache(). Aborting.
then try
hash -r
the following worked for me:
sudo apt remove cmake
pip install cmake --upgrade
then, I exited the terminal and again entered to check the version with cmake --version command
3.20.5 in ubuntu 16.04
wget -O - https://apt.kitware.com/keys/kitware-archive-latest.asc 2>/dev/null | gpg --dearmor - | sudo tee /etc/apt/trusted.gpg.d/kitware.gpg >/dev/null
sudo apt-add-repository 'deb https://apt.kitware.com/ubuntu/ xenial main'
sudo apt update
apt-key adv --keyserver keyserver.ubuntu.com --recv-keys DE19EB17684BA42D
sudo apt install cmake cmake-qt-gui cmake-curses-gui
yum remove cmake
wget https://github.com/Kitware/CMake/releases/download/v3.13.4/cmake-3.13.4.tar.gz
tar zxvf cmake-3.13.4.tar.gz
cd cmake-3.13.4
sudo ./bootstrap --prefix=/usr/local
sudo make
sudo make install
vi ~/.bash_profile
...
# PATH=$PATH:$HOME/bin
PATH=/usr/local/bin:$PATH:$HOME/bin
export PATH
source ~/.bash_profile
cmake --version
vi ~/.bash_profile
centos7 it help me
In case someone still finds it hard to remove cmake from their machine.
This command works for me (requires sudo permissions):
$ sudo find / -name "cmake" | xargs -I % sudo rm -rf "%"

Wine 1.9.24 on Centos 7

The problem
When I try to start any windows program I get no error and nothing happens. I tried on 3 different machines with Centos 7. Also tried older versions of Wine. Tested with winbox.exe from Mikrotik and with putty.exe. What could be the problem?
$ ./wine winbox.exe
$
CentOS 7 version
$ cat /etc/*elease | grep "release" | head -1
CentOS Linux release 7.3.1611 (Core)
Kernel version
$ uname -r
3.10.0-514.2.2.el7.x86_64
Openbox version
$ openbox --version | grep "Openbox"
Openbox 3.5.2
Wine install steps
sudo yum clean all
sudo yum update -y
sudo yum groupinstall -y 'Development Tools'
sudo yum install -y libX11-devel freetype-devel zlib-devel libxcb-devel libxml2-devel libxslt-devel libjpeg-devel gnutls-devel flex bison
cd /tmp
wget http://dl.winehq.org/wine/source/1.9/wine-1.9.24.tar.bz2
tar xjf wine-1.9.24.tar.bz2
cd wine-1.9.24
./configure --enable-win64
make -j4
and the executable is working
$ ./wine --version
wine-1.9.24
wine-2.0-rc3
Had no time to try the latest Wine 2.0 version, but all my problems are gone with wine-2.0-rc3. Tested only 32bit install. Step by step:
sudo yum clean all
sudo yum update -y
sudo yum groupinstall -y 'Development Tools'
sudo yum install -y libX11-devel freetype-devel zlib-devel libxcb-devel libxml2-devel libxslt-devel libjpeg-devel gnutls-devel flex bison
sudo yum install -y samba-winbind samba-winbind-clients samba-winbind-modules libwbclient-devel mod_auth_ntlm_winbind
# OpenGL support
sudo yum install mesa-dri-drivers.i686 mesa-libGL.i686
mkdir ~/bin && cd ~/bin
wget http://dl.winehq.org/wine/source/2.0/wine-2.0-rc3.tar.bz2
tar xjf wine-2.0-rc3.tar.bz2 && cd wine-2.0-rc3
# run provided install tool and write the output to file
./tools/wineinstall | tee output.file
# get the winetricks tool
wget https://raw.githubusercontent.com/Winetricks/winetricks/master/src/winetricks
chmod +x winetricks
WINE=~/bin/wine-2.0-rc3/wine sh winetricks corefonts vcrun6 mfc40 ie8 ie7
# start the downloaded windows program
./wine ~/Downloads/winbox.exe
winbox from Mikrotik
SketchUp

Tess4J on Ubuntu Linux, UnsatisfiedLinkError

I am getting a getting an UnsatisfiedLinkError using Tess4j in Tomcat+Ubuntu(Linux)
java.lang.UnsatisfiedLinkError: Error looking up function 'TessBaseAPICreate': /usr/lib/libtesseract.so.3.0.2: undefined symbol: TessBaseAPICreate
at com.sun.jna.Function.<init>(Function.java:208)
at com.sun.jna.NativeLibrary.getFunction(NativeLibrary.java:536)
at com.sun.jna.NativeLibrary.getFunction(NativeLibrary.java:513)
at com.sun.jna.NativeLibrary.getFunction(NativeLibrary.java:499)
Library is installed via apt-get install tesseract-ocr, Tess4j version is 2.0.0, everything seems to work on a MacOS/OracleJDK1.7(64bits), but not in Ubuntu/Linux/OracleJDK1.7(64bits)
Some stackoverflow-search gives clues about wrong versions or library not present, but the library is right there...
ls -al /usr/lib/libtesseract.so.3.0.2
-rw-r--r-- 1 root root 4219544 Feb 25 2012 /usr/lib/libtesseract.so.3.0.2
Someone with a solution or a hint?
Tess4J 2.0 is compatible with Tesseract 3.03RC. Since yours is 3.02, you'd need Tess4J 1.x version.
this may be the version of tesseract is not compatible to ubuntu version
as to me my program runs in win10 and ubuntu 16 has no error ,but when in ubuntu 12.04 this error occurs
maybe I install tesseract by the command
sudo apt-get install tesseract-ocr
but indeed in ubuntu 12 after i install by the flow
sudo apt-get install libpng-dev libjpeg-dev libtiff-dev zlib1g-dev
sudo apt-get install gcc g++
sudo apt-get install autoconf automake libtool checkinstall
Install Leptonica from source. The latest version as of writing is 1.69.
wget http://www.leptonica.org/source/leptonica-1.69.tar.gz (if you can't,download leptonica-1.69.tar.gz from the internet)
tar -zxvf leptonica-1.69.tar.gz
cd leptonica-1.69
./configure
make
sudo checkinstall
sudo ldconfig
Then install Tesseract OCR from source.
wget https://tesseract-ocr.googlecode.com/files/tesseract-ocr-3.02.02.tar.gz
(maybe you can download tesseract-ocr-3.02.02.tar.gz from the internet and then upload to the server )
tar -zxvf tesseract-ocr-3.02.02.tar.gz
cd tesseract-ocr
./autogen.sh
./configure
make (this may take a while)
sudo make install
sudo ldconfig
after this i solve this problem

How can I set up & run PhantomJS on Ubuntu?

I set up PhantomJS and recorded it to video: https://www.dailymotion.com/video/xnizmh_1_webcam
Build instructions: http://phantomjs.org/build.html
Is there anything wrong in my setup?
After I set it up I read the quick start tutorial and tried to write this code
phantomjs hello.js
It gives me "command not found" error. How can I solve this problem?
Guidouil's answer put me on the right track. I had to add one additional symlink to /usr/bin/, and I did direct symlinks for all 3 - see below.
I'm installing on Ubuntu server Natty Narwhal.
This is exactly what I did.
cd /usr/local/share
sudo wget https://bitbucket.org/ariya/phantomjs/downloads/phantomjs-1.9.7-linux-x86_64.tar.bz2
sudo tar xjf phantomjs-1.9.7-linux-x86_64.tar.bz2
sudo ln -s /usr/local/share/phantomjs-1.9.7-linux-x86_64/bin/phantomjs /usr/local/share/phantomjs
sudo ln -s /usr/local/share/phantomjs-1.9.7-linux-x86_64/bin/phantomjs /usr/local/bin/phantomjs
sudo ln -s /usr/local/share/phantomjs-1.9.7-linux-x86_64/bin/phantomjs /usr/bin/phantomjs
And finally when I do
phantomjs -v
I get 1.9.7
If anyone sees any problems with what I've done, please let me know.
PhantomJS is on npm. You can run this command to install it globally:
npm install -g phantomjs-prebuilt
phantomjs -v should return 2.1.1
download from phantomjs website the prebuilt package :
http://phantomjs.org/download.html
then open a terminal and go to the Downloads folder
sudo mv phantomjs-1.8.1-linux-x86_64.tar.bz2 /usr/local/share/.
cd /usr/local/share/
sudo tar xjf phantomjs-1.8.1-linux-x86_64.tar.bz2
sudo ln -s /usr/local/share/phantomjs-1.8.1-linux-x86_64 /usr/local/share/phantomjs
sudo ln -s /usr/local/share/phantomjs/bin/phantomjs /usr/local/bin/phantomjs
then to check install phantomjs -v should return 1.8.1
Install from package manager:
sudo apt-get install phantomjs
Here are the build steps I used (note these instructions are for version 1.3. See comments to this answer for the installation instructions of the latest PhantomJS):
sudo apt-get update
sudo apt-get install git-core
sudo apt-get install build-essential
sudo apt-get install libqt4-dev libqtwebkit-dev qt4-qmake
git clone git://github.com/ariya/phantomjs.git && cd phantomjs
git checkout 1.3
qmake-qt4 && make
Now install Xvfb
sudo apt-get install xvfb xfonts-100dpi xfonts-75dpi xfonts-scalable xfonts-cyrillic
Launch Xvfb:
Xvfb :23 -screen 0 1024x768x24 &
Now run phantom:
DISPLAY=:23 ./phantomjs hello.js
For PhantomJS version above 1.5, consider this (verbatim copy of the build instructions on the phantom website):
For Ubuntu Linux (tested on a barebone install of Ubuntu 10.04 Lucid
Lynx and Ubuntu 11.04 Natty Narwhal):
sudo apt-get install build-essential chrpath git-core libssl-dev libfontconfig1-dev
git clone git://github.com/ariya/phantomjs.git
cd phantomjs
git checkout 1.7
./build.sh
For Ubuntu you can use the prebuilt versions downloadable from the PhantomJS site.
If you have some serious time on your hands you can also build it yourself. (This is exactly the procedure from Nikhil's answer).
The guys over at PhantomJS recommend using the binaries to save time:
Warning: Compiling PhantomJS from source takes a long time, mainly due to thousands of files in the WebKit module. With 4 parallel compile jobs on a modern machine, the entire process takes roughly 30 minutes. It is highly recommended to download and install the ready-made binary package if it is available.
With a modern machine they mean > 4 cores, > 8gb mem I think. I tried it on a micro AWS instance and gave up after 2 hours.
In short: install the prebuilt packages from the PhantomJS site per their instructions.
Personaly I prefer using npm (see Arnel Bucio answer)
sudo npm install -g phantomjs
but! I noticed that some of npm module still can't see it as global executable.
so!
Create new /usr/share/phantomjs/ directory link
cd /usr/share
sudo ln -s ../lib/node_modules/phantomjs/lib/phantom phantomjs
Remove old /usr/bin/phantomjs executable link and create the new one
cd /usr/bin
sudo mv phantomjs phantomjs.old
sudo ln -s ../share/phantomjs .
in my vagrant bootstrap:
apt-get install -y build-essential chrpath git-core libssl-dev libfontconfig1-dev
git clone git://github.com/ariya/phantomjs.git
cd phantomjs
git checkout 1.9
echo y | ./build.sh
ln -s /home/vagrant/phantomjs/bin/phantomjs /usr/local/bin/phantomjs
cd ..
I have done with this.
sudo apt-get update
sudo apt-get install build-essential chrpath git-core libssl-dev libfontconfig1-dev
git clone git://github.com/ariya/phantomjs.git
cd phantomjs
git checkout 1.9
./build.sh
See link
Installation guide is in ...
https://gist.github.com/julionc/7476620
And run in terminal with this command
phantomjs --webdriver=4444
From the official site: phantomjs site
sudo apt-get install build-essential chrpath git-core libssl-dev libfontconfig1-dev
git clone git://github.com/ariya/phantomjs.git
cd phantomjs
git checkout 1.8
./build.sh
For Ubuntu, download the suitable file from http://phantomjs.org/download.html. CD to the downloaded folder. Then:
sudo tar xvf phantomjs-1.9.0-linux-x86_64.tar.bz2
sudo mv phantomjs-1.9.0-linux-x86_64 /usr/local/share/phantomjs
sudo ln -s /usr/local/share/phantomjs/bin/phantomjs /usr/bin/phantomjs
Make sure to replace the file name in these commands with the file you have downloaded.
Be aware this is definitely one way to do it:
$ sudo apt-get install phantomjs
$ phantomjs -v
1.6.0
Sadly, it installs 1.6 and not the latest one, but this works for my purposes.
I know this is too old, but, just i case someone gets to this question from Google now, you can install it by typing apt-get install phantomjs
On Ubuntu for Windows, I found neither apt-get nor npm versions worked for me. What worked was the script from this comment.
For ease of use, I pasted the whole thing into a script file called install_phantomjs.sh, made it executable (chmod u+x install_phantomjs.sh), and then ran it (./install_phantomjs.sh)
Or the latest - 32bit version Linux
sudo wget http://phantomjs.googlecode.com/files/phantomjs-1.9.2-linux-i686.tar.bz2
sudo ln -s /usr/local/share/phantomjs-1.9.2-linux-i686/bin/phantomjs /usr/local/share/phantomjs
sudo ln -s /usr/local/share/phantomjs-1.9.2-linux-i686/bin/phantomjs /usr/local/bin/phantomjs
sudo ln -s /usr/local/share/phantomjs-1.9.2-linux-i686/bin/phantomjs /usr/bin/phantomjs
Installation and Calling Phantomjs
Follow the steps doesn't work, but cloned from others built. (ver2.0)
Bellow the installation procedure by Julio Napurí https://gist.github.com/julionc
Version: 1.9.8
Platform: x86_64
First, install or update to the latest system software.
sudo apt-get update
sudo apt-get install build-essential chrpath libssl-dev libxft-dev
Install these packages needed by PhantomJS to work correctly.
sudo apt-get install libfreetype6 libfreetype6-dev
sudo apt-get install libfontconfig1 libfontconfig1-dev
Get it from the PhantomJS website.
cd ~
export PHANTOM_JS="phantomjs-1.9.8-linux-x86_64"
wget https://bitbucket.org/ariya/phantomjs/downloads/$PHANTOM_JS.tar.bz2
sudo tar xvjf $PHANTOM_JS.tar.bz2
Once downloaded, move Phantomjs folder to /usr/local/share/ and create a symlink:
sudo mv $PHANTOM_JS /usr/local/share
sudo ln -sf /usr/local/share/$PHANTOM_JS/bin/phantomjs /usr/local/bin
Now, It should have PhantomJS properly on your system.
phantomjs --version
I have found this simpler way - Phantom dependencies + Npm
sudo apt-get update
sudo apt-get install build-essential chrpath libssl-dev libxft-dev
sudo apt-get install libfreetype6 libfreetype6-dev
sudo apt-get install libfontconfig1 libfontconfig1-dev
and npm
[sudo] npm install -g phantomjs
Done.
On linux to run hello.js don't forget to add the path of hello.js:
phantomjs YourPathToPhantomjsFolder/examples/hello.js
If you want to use phantomjs easily, you can use it at phantomjscloud.com
You can get the result just by http request.
This is how I place a specific version of phantomjs in /usr/local/bin on my docker containers.
curl -Ls https://github.com/Medium/phantomjs/releases/download/v1.9.19/phantomjs-1.9.8-linux-x86_64.tar.bz2 \
| tar jxvf - --strip-components=2 -C /usr/local/bin/ ./phantomjs-1.9.8-linux-x86_64/bin/phantomjs
or with out ./ depending on OS.
curl -Ls https://github.com/Medium/phantomjs/releases/download/v1.9.19/phantomjs-1.9.8-linux-x86_64.tar.bz2 \
| tar jxvf - --strip-components=2 -C /usr/local/bin/ phantomjs-1.9.8-linux-x86_64/bin/phantomjs
You can get up and running without sudo or npm. Simply download, extract, and add to path.
This has the added advantage of easy backup if you are in the habit of backing up your entire home folder which I highly recommend. This also works with any version of Linux.
➤ cd ~
➤ wget https://bitbucket.org/ariya/phantomjs/downloads/phantomjs-2.1.1-linux-x86_64.tar.bz2
➤ mkdir phantomjs
➤ tar xjf phantomjs-2.1.1-linux-x86_64.tar.bz2 -C phantomjs
➤ echo 'export PATH="$PATH:$HOME/phantomjs/bin"' >> .profile
➤ source .profile
➤ phantomjs -v
2.1.1
The disadvantages are:
You will need to manually upgrade
Other users will not have access to this.
You could use a very simple shell script for installing/upgrading
#!/bin/sh
# install_phantomjs.sh $VERSION
$VERSION = $1
printf "Downloading PhantomJS $VERSION...\n"
wget "https://bitbucket.org/ariya/phantomjs/downloads/phantomjs-$VERSION-linux-x86_64.tar.bz2"
printf "Extracting PhantomJS $VERSION to ~/phantomjs...\n"
mkdir ~/phantomjs
tar xjf phantomjs-$VERSION-linux-x86_64.tar.bz2 -C ~/phantomjs
printf "Done! Make sure $HOME/phantomjs/bin is in your path.\n"
Or in a Dockerfile
# Download and setup PhantomJS
ENV PHANTOMJS_VERSION 2.1.1
RUN curl -fSL "https://bitbucket.org/ariya/phantomjs/downloads/phantomjs-$PHANTOMJS_VERSION-linux-x86_64.tar.bz2" -o /tmp/phantomjs.tar.bz2 && \
mkdir ~/phantomjs && \
tar xjf /tmp/phantomjs.tar.bz2 -C ~/phantomjs && \
rm /tmp/phantomjs.tar.bz2
ENV PATH /home/$USERNAME/phantomjs/bin:$PATH
Here is what I did
on my ubuntu 16.04 machine
sudo apt-get update
sudo wget https://bitbucket.org/ariya/phantomjs/downloads/phantomjs-2.1.1-linux-x86_64.tar.bz2
sudo mv path/where/you/downloaded/phantomjs /usr/bin
and finally when I do
phantomjs -v
I get 2.1.1
After going through every answer of this thread. I think this is the best solution for installing and running phantomjs in ubuntu.

Resources