How can I set up & run PhantomJS on Ubuntu? - linux

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.

Related

Docker - No rule to make target `hiredis'

I have been scratching my head since past 2 days for this issue. I am using amazon linux image and trying to install redis through a Dockerfile, but this doesn't work.
RUN yum install -y java-17-amazon-corretto.x86_64
RUN yum install -y tar
RUN yum install -y wget
RUN yum -y update
RUN yum -y install gcc make
RUN wget http://download.redis.io/redis-stable.tar.gz
RUN tar xvzf redis-stable.tar.gz
RUN cd redis-stable/deps
make hiredis jemalloc linenoise lua geohash-int
cd ..
make install
When I follow the docs, it says run make and make install from the root of the install directory.
RUN cd redis-stable
RUN make
RUN make install

Setting Up a Debian Docker image with older boost library

I have an already compiled Linux app which has become dated. To use it, I want to create a Docker image and an appropriate environment to work with. My problem is that is app requires an older version of the boost libraries. 1.57.0 to be specific.
I have been able to get boost installed (I believe correctly) but the app errors out.
The error that I am getting is:
undefined symbol: _ZN5boost15program_options3argE
I am hoping someone has experience with this. Briefly, my pipeline is:
get the rocker/verse Docker image that has Debian and R and some more goodies I need.
Bash in to it, apt-get install ... etc.
sudo apt-get update && sudo apt-get upgrade
sudo apt-get install build-essential g++ python-dev autotools-dev libicu-dev build-essential libbz2-dev libboost-all-dev
cd home
wget -O boost_1_57_0.tar.gz https://sourceforge.net/projects/boost/files/boost/1.57.0/boost_1_57_0.tar.gz/download
tar xzvf boost_1_57_0.tar.gz
cd boost_1_57_0
./bootstrap.sh --with-libraries=atomic,chrono,context,coroutine,container,date_time,exception,filesystem,graph,graph_parallel,iostreams,locale,log,math,mpi,program_options,python,random,regex,serialization,signals,system,test,thread,timer,wave
./b2 toolset=gcc cxxflags=-std=gnu++0x
sudo ./b2 install
sudo apt-get update && sudo apt-get upgrade && sudo apt-get dist-upgrade
-----Edit: added additional bash code that was missing here
sudo sh -c 'echo "/usr/local/lib" >> /etc/ld.so.conf.d/local.conf’

How to yum install Node.JS on Amazon Linux

I've seen the writeup on using yum to install the dependencies, and then installing Node.JS & NPM from source. While this does work, I feel like Node.JS and NPM should both be in a public repo somewhere.
How can I install Node.JS and NPM in one command on AWS Amazon Linux?
Stumbled onto this, was strangely hard to find again later. Putting here for posterity:
sudo yum install nodejs npm --enablerepo=epel
EDIT 3: As of July 2016, EDIT 1 no longer works for nodejs 4 (and EDIT 2 neither). This answer (https://stackoverflow.com/a/35165401/78935) gives a true one-liner.
EDIT 1: If you're looking for nodejs 4, please try the EPEL testing repo:
sudo yum install nodejs --enablerepo=epel-testing
EDIT 2: To upgrade from nodejs 0.12 installed through the EPEL repo using the command above, to nodejs 4 from the EPEL testing repo, please follow these steps:
sudo yum rm nodejs
sudo rm -f /usr/local/bin/node
sudo yum install nodejs --enablerepo=epel-testing
The newer packages put the node binaries in /usr/bin, instead of /usr/local/bin.
And some background:
The option --enablerepo=epel causes yum to search for the packages in the EPEL repository.
EPEL (Extra Packages for Enterprise Linux) is open source and free community based repository project from Fedora team which provides 100% high quality add-on software packages for Linux distribution including RHEL (Red Hat Enterprise Linux), CentOS, and Scientific Linux. Epel project is not a part of RHEL/Cent OS but it is designed for major Linux distributions by providing lots of open source packages like networking, sys admin, programming, monitoring and so on. Most of the epel packages are maintained by Fedora repo.
Via http://www.tecmint.com/how-to-enable-epel-repository-for-rhel-centos-6-5/
Like others, the accepted answer also gave me an outdated version.
Here is another way to do it that works very well:
$ curl --silent --location https://rpm.nodesource.com/setup_16.x | bash -
$ yum -y install nodejs
You can also replace the 16.x with another version, such as 18.x, 14.x, etc.
You can see all available versions on the NodeSource Github page, and pull from there as well if desired.
Note: you may need to run using sudo depending on your environment.
The accepted answer gave me node 0.10.36 and npm 1.3.6 which are very out of date. I grabbed the latest linux-x64 tarball from the nodejs downloads page and it wasn't too difficult to install: https://nodejs.org/dist/latest/.
# start in a directory where you like to install things for the current user
(For noobs : it downloads node package as node.tgz file in your directlry)
curl (paste the link to the one you want from the downloads page) >node.tgz
Now upzip the tar you just downloaded -
tar xzf node.tgz
Run this command and then also add it to your .bashrc:
export PATH="$PATH:(your install dir)/(node dir)/bin"
(example : export PATH ="$PATH:/home/ec2-user/mydirectory/node/node4.5.0-linux-x64/bin")
And update npm (only once, don't add to .bashrc):
npm install -g npm
Note that the -g there which means global, really means global to that npm instance which is the instance we just installed and is limited to the current user. This will apply to all packages that npm installs 'globally'.
Simple install with NVM...
curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.2/install.sh | bash
. ~/.nvm/nvm.sh
nvm install node
To install a certain version (such as 18.12.1) of Node change the last line to
nvm install 18.12.1
For more information about how to use NVM visit the docs:
https://github.com/nvm-sh/nvm
The procedure that worked for me (following these rather old instructions with a few updates):
check git is installed git --version or install it via:
sudo yum install git
install gcc and openssl:
sudo yum install gcc-c++ make
sudo yum install openssl-devel
clone the git repo into a directory called node (which you can remove later):
git clone https://github.com/nodejs/node.git
decide which version of node you want at https://github.com/nodejs/node/releases
go to the node directory just created and install node
cd node
git checkout v6.1.0 - put your desired version after the v
./configure
make
sudo make install
test that node is installed / working with either node --version or simply node (exit node via process.exit() or ^C x 2 or ^C + exit)
check the npm version: npm --version and update if necessary via sudo npm install -g npm
Optional: remove the node directory with rm -r node
Notes:
The accepted answer didn't work since sudo yum install nodejs --enablerepo=epel-testing returns the error: No package nodejs available.
...and sudo yum install nodejs --enablerepo=epel (ie without -testing) only gave very old versions.
If you already have an old version of node installed you can remove it with:
sudo npm uninstall npm -g ...since npm can uninstall itself
sudo yum erase nodejs
sudo rm -f /usr/local/bin/node
(sudo yum rm nodejs in the accepted answer won't work as rm is not a valid yum command see yum --help)
It's possible to clone the node repo via git clone git://github.com/nodejs/node.git rather than git clone https://github.com/nodejs/node.gitbut you may get a various errors (see here).
If you already have a /node dir from a previous install, remove it before using the git clone command (or there'll be a conflict):
rm -r node
If you have trouble with any sudo npm... command - like sudo: npm: command not found and/or have permissions issues installing node packages without sudo, edit sudo nano /etc/sudoers and add :/usr/local/bin to the end of the line Defaults secure_path = /sbin:/bin:/usr/sbin:/usr/bin so that it reads Defaults secure_path = /sbin:/bin:/usr/sbin:/usr/bin:/usr/local/bin
Seems no one is mentioning this. On Amazon Linux 2, official way to load EPEL is:
sudo amazon-linux-extras install epel
...then you may:
sudo yum install nodejs
See Extras Library (Amazon Linux 2)
For the v4 LTS version use:
curl --silent --location https://rpm.nodesource.com/setup_4.x | bash -
yum -y install nodejs
For the Node.js v6 use:
curl --silent --location https://rpm.nodesource.com/setup_6.x | bash -
yum -y install nodejs
I also ran into some problems when trying to install native addons on Amazon Linux. If you want to do this you should also install build tools:
yum install gcc-c++ make
I just came across this. I tried a few of the more popular answers, but in the end, what worked for me was Amazon's quick setup guide.
Tutorial: Setting Up Node.js on an Amazon EC2 Instance
The gist of the tutorial is:
Make sure you are ssh'd onto the instance.
Grab nvm: curl -o- https://raw.githubusercontent.com/creationix/nvm/v0.32.0/install.sh | bash
Active . ~/.nvm/nvm.sh
Install node using nvm nvm install 4.4.5 (NOTE: You can choose a different version. Check out the remote versions first by running $ nvm ls-remote)
Finally, test that you have installed node Node correctly by running $ node -e "console.log('Running Node.js' + process.version)"
Hopefully this helps the next person.
RHEL, CentOS, CloudLinux, Amazon Linux or Fedora:
# As root
curl -fsSL https://rpm.nodesource.com/setup_12.x | bash -
# No root privileges
curl -fsSL https://rpm.nodesource.com/setup_12.x | sudo bash -
sudo yum install -y nodejs
I had Node.js 6.x installed and wanted to install Node.js 8.x.
Here's the commands I used (taken from Nodejs's site with a few extra steps to handle the yum cached data):
sudo yum remove nodejs: Uninstall Node.js 6.x (I don't know if this was necessary or not)
curl --silent --location https://rpm.nodesource.com/setup_8.x | sudo bash -
sudo yum clean all
sudo yum makecache: Regenerate metadata cache (this wasn't in the docs, but yum kept trying to install Node.jx 6.x, unsuccessfully, until I issued these last two commands)
sudo yum install nodejs: Install Node.js 8.x
sudo yum install nodejs npm --enablerepo=epel works for Amazon Linux AMI.
curl --silent --location https://rpm.nodesource.com/setup_6.x | bash -
yum -y install nodejs
works for RedHat.
The easiest solution is this( do these as root)
sudo su root
cd /etc
mkdir node
yum install wget
wget https://nodejs.org/dist/v9.0.0/node-v9.0.0-linux-x64.tar.gz
tar -xvf node-v9.0.0-linux-x64.tar.gz
cd node-v9.0.0-linux-x64/bin
./node -v
ln -s /etc/node-v9.0.0-linux-x64/bin/node node
https://nodejs.org/en/download/package-manager/#debian-and-ubuntu-based-linux-distributions
curl --silent --location https://rpm.nodesource.com/setup_10.x | sudo bash -
sudo yum -y install nodejs
Official Documentation for EC2-Instance works for me: https://docs.aws.amazon.com/sdk-for-javascript/v2/developer-guide/setting-up-node-on-ec2-instance.html
1. curl -o- https://raw.githubusercontent.com/creationix/nvm/v0.32.0/install.sh | bash
2. . ~/.nvm/nvm.sh
3. nvm ls-remote (=> find your version x.x.x =>) nvm install x.x.x
4. node -e "console.log('Running Node.js ' + process.version)"
MAY 2022
I spent way too long on this. My Amazon Linux 2 configuration, running as root.
#!/usr/bin/env zsh
# https://stackoverflow.com/questions/11542846/nvm-node-js-recommended-install-for-all-users
echo "=================================N=O=D=E========================================"
cd /usr/local/bin || exit 90
git clone https://github.com/nvm-sh/nvm.git .nvm
\. "/usr/local/bin/.nvm/nvm.sh"
nvm install --lts
node -e "console.log('Running Node.js ' + process.version)"
cat << "EOF" > /etc/profile.d/npm.sh
#!/usr/bin/env bash
export NVM_DIR="/usr/local/bin/.nvm"
[ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh" # This loads nvm'}
EOF
chmod 755 /etc/profile.d/npm.sh
npm install -g npm
June 2022 - The system really hates when things arn't linked in the bin. Here's a small update to help if you need things accessible by other users. Admittedly adding /etc/profile.d/npm.sh is just what nvm suggests, but I find it over-rated. I think it could be removed in place of purely the ln -s. happy hacking
#!/bin/zsh
# https://stackoverflow.com/questions/11542846/nvm-node-js-recommended-install-for-all-users
echo "=================================N=O=D=E========================================"
cd /usr/local/bin || exit 90
git clone https://github.com/nvm-sh/nvm.git .nvm
# this uncontrolled script has an unbound variable $HOME
# #link https://github.com/Drop-In-Gaming/dropingaming.com/runs/6437329820?check_suite_focus=true
\. "/usr/local/bin/.nvm/nvm.sh" || true
# todo - try to install 18
nvm install --lts
nvm install 17
node -e "console.log('Running Node.js ' + process.version)"
cat << "EOF" > /etc/profile.d/npm.sh
#!/usr/bin/env bash
export NVM_DIR="/usr/local/bin/.nvm"
[ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh" # This loads nvm'}
EOF
echo 'source /etc/profile.d/npm.sh' >> /root/.bashrc
echo 'source /etc/profile.d/npm.sh' >> /root/.zshrc
echo 'source /etc/profile.d/npm.sh' >> /home/ssm-user/.bashrc
echo 'source /etc/profile.d/npm.sh' >> /home/ssm-user/.zshrc
echo 'source /etc/profile.d/npm.sh' >> /home/www-data/.bashrc
echo 'source /etc/profile.d/npm.sh' >> /home/www-data/.zshrc
chmod 755 /etc/profile.d/npm.sh
npm install -g npm
echo "===========================WHERE==IS==NODE==========================="
which node
which npm
echo "symlinking to /usr/bin/"
if [ -e /usr/bin/node ]; then
sudo rm -f /usr/bin/node
fi
if [ -e /usr/bin/npm ]; then
sudo rm -f /usr/bin/npm
fi
sudo ln -s "$(which node)" /usr/bin/
sudo ln -s "$(which npm)" /usr/bin/
For those who want to have the accepted answer run in Ansible without further searches, I post the task here for convenience and future reference.
Accepted answer recommendation: https://stackoverflow.com/a/35165401/78935
Ansible task equivalent
tasks:
- name: Setting up the NodeJS yum repository
shell: curl --silent --location https://rpm.nodesource.com/setup_10.x | bash -
args:
warn: no
# ...
As others mentioned using epel gives a really outdated version, here is a little script I just wrote instead to add to the CI pipeline or pass it to ec2 user-data to install the latest version of node, simply replace the version with what you want, and the appropriate distro of Linux you are using.
The following example is for amazon-Linux-2-AMI
#!/bin/bash
version='v14.13.1'
distro='linux-x64'
package_name="node-$version-$distro"
package_location="/usr/local/lib/"
curl -O https://nodejs.org/download/release/latest/$package_name.tar.gz
tar -xvf $package_name.tar.gz -C $package_location
rm -rfv $package_name.tar.gz
echo "export PATH=$package_location/$package_name/bin:\$PATH" >> ~/.profile
if you want to test it in the same shell simply run
. ~/.profile
I usually use NVM to install node on server. It gives me option to install multiple version of nodejs.
Commands are given below :
curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.35.3/install.sh | bash
then check if it's installed properly using :
command -v nvm
after that, run this to install latest version :
nvm install node
or
nvm install 11
As mentioned in official documentation , simple below 2 steps -
curl -sL https://deb.nodesource.com/setup_10.x | sudo -E bash -
sudo apt-get install -y nodejs
You can update/install the node by reinstalling the installed package to the current version which may save us from lotta of errors, while doing the update.
This is done by nvm with the below command. Here, I have updated my node version to 8 and reinstalled all the available packages to v8 too!
nvm i v8 --reinstall-packages-from=default
It works on AWS Linux instance as well.
As stated in the Amazon docs (Setting Up Node.js on an Amazon EC2 Instance), just run the following commands:
curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.34.0/install.sh | bash
. ~/.nvm/nvm.sh
nvm install --lts
Done!

Can't install node.js on Linux server

I followed some instructions to install node.js on a Linux server and ran in to the following blocks. I started out by doing sudo apt-get install python-software-properties and that worked fine. Then, I did sudo add-apt-repository ppa:chris-lea/node.js. But, wait - there is no command add-apt-repository. OK, so I looked it up and it told me to do apt-get install software-properties-common and that would have been fine, except it gave me this error:
Reading package lists... Done
Building dependency tree
Reading state information... Done
E: Unable to locate package software-properties-common
Well, what can I do to get node.js on my server? Obviously, none of this works and it's Debian, in case you were wondering. I really need help on this. Basically, how can I install software-properties-common if it does not exist? It just won't show up.
For a Debian install of the latest node.js, you should follow these instructions, not requiring you to add the PPA:
sudo apt-get install python g++ make checkinstall
mkdir ~/src && cd $_
wget -N http://nodejs.org/dist/node-latest.tar.gz
tar xzvf node-latest.tar.gz && cd node-v*
./configure
checkinstall #(remove the "v" in front of the version number in the dialog)
sudo dpkg -i node_*
UPDATE: I wrote this a long time ago. Since then, I find using nvm a much less painful way to get node onto machines. As per link, steps are basically reduced to:
curl -o- https://raw.githubusercontent.com/creationix/nvm/v0.33.0/install.sh | bash
nvm install node

node js can't install right on my Ubuntu computer

I use the git to install node js, the method I use is below:
mkdir ~/local
echo 'export PATH=$HOME/local/bin:$PATH' >> ~/.bashrc
. ~/.bashrc
git clone git://github.com/joyent/node.git
cd node
./configure --prefix=~/local
make install
cd ..
After this, I use node on my command line, it tell me no node.Any one can help me?
I got the method form https://gist.github.com/isaacs/579814, but can't work.
My path is here.
You have to make before you make install.
The wiki has more information about building from source.
I used NVM to install Node.js to my Ubuntu computer:
First install these packages
sudo apt-get install curl build-essential libssl-dev libxml2 libxml2-dev libexpat1-dev
Install nvm
git clone https://github.com/creationix/nvm.git ~/.nvm
To activate nvm, you need to source it from your bash shell (e.g, add to your ~/.bash_profile)
. ~/.nvm/nvm.sh
The following steps are also required when upgrading Node
Install Node (use whichever version you like, but v0.8.x works)
nvm install v0.8.23
nvm alias default v0.8.23
nvm use v0.8.23
Any issues, I would check out the NVM repo.
This is my build script for node.js on ubuntu. I don't build from the bleeding edge most recent code, but its close to your process.
sudo apt-get update
sudo apt-get -y install build-essential libssl-dev
wget http://nodejs.org/dist/latest/docs/
node_version=`grep -i 'current version' index.html | sed -E 's/.*([0-9]+\.[0-9]+\.[0-9]+).*/\1/'`
wget http://nodejs.org/dist/v$node_version/node-v$node_version.tar.gz
tar -xzf node-v$node_version.tar.gz
cd node-v$node_version
./configure
make
sudo make install
cd ..
rm -rf node-v$node_version.tar.gz node-v$node_version index.html

Resources