0

I tried to use pip install, but it tells cannot find such package.

I also see someone say we can use brew and nodejs to install. This is what I tried to install brew

/usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"

It returns that ruby doesn't found.

I have no idea about nodejs.

Anyone knows how can I install PhantomJS in the server?

Chandan Rai
  • 9,879
  • 2
  • 20
  • 28
Gang
  • 85
  • 2
  • 9

2 Answers2

0

Meet npm!

Npm stands for Node Package Manager. You can install packages for using them from the CLI or from your nodejs app.

You can install NPM from here.

If node isn't installed yet, you can use NVM, which makes it really easy -

$ curl -o- https://raw.githubusercontent.com/creationix/nvm/v0.33.2/install.sh | bash

For your question, See this specific package. You can install it via:

$ npm install phantomjs-prebuilt

And then you should be able to: $ bin/phantomjs [phantom arguments] to run phantomJS from the terminal.

Eyal Cohen
  • 1,188
  • 2
  • 15
  • 27
  • You know I can't open a browser in vps, right? So how can I install NPM? Just download the msi and upload it to the server? – Gang Jul 15 '17 at 19:10
  • What kind of OS running on your vps? Windows? – Eyal Cohen Jul 15 '17 at 19:12
  • I'm not familiar with vps. My friend gave me that. But absolutely not windows. I logged in with ssh. It looks like a terminal. There is no apt-get command. So I don't think it is ubuntu or centos as well. – Gang Jul 15 '17 at 19:22
  • can you paste the output of `cat /etc/*-release` here please so I can help you? – Eyal Cohen Jul 15 '17 at 19:31
  • Wow, it is centos. – Gang Jul 15 '17 at 19:36
  • CentOS Linux release 7.1.1503 (Core) NAME="CentOS Linux" VERSION="7 (Core)" ID="centos" ID_LIKE="rhel fedora" VERSION_ID="7" PRETTY_NAME="CentOS Linux 7 (Core)" ANSI_COLOR="0;31" CPE_NAME="cpe:/o:centos:centos:7" HOME_URL="https://www.centos.org/" BUG_REPORT_URL="https://bugs.centos.org/" CENTOS_MANTISBT_PROJECT="CentOS-7" CENTOS_MANTISBT_PROJECT_VERSION="7" REDHAT_SUPPORT_PRODUCT="centos" REDHAT_SUPPORT_PRODUCT_VERSION="7" CentOS Linux release 7.1.1503 (Core) CentOS Linux release 7.1.1503 (Core) – Gang Jul 15 '17 at 19:36
  • so follow the installation process of node and phantom I explained at the answer. After you install node, running `$ npm install ...` should be available. Let me know if you're still stuck. – Eyal Cohen Jul 15 '17 at 19:38
  • Still cannot install npm. I tried lots of methods. https://stackoverflow.com/questions/45126818/how-to-install-npm-on-centos7-vps-server – Gang Jul 16 '17 at 17:14
0

PhantomJS is a standalone application with its own website which has binaries for all major platforms and documentation. You don't really need pip or npm or bundler to install it, just do it manually.

  1. Go to http://phantomjs.org/download.html

Choose the appropriate binary (Linux x32 x64 / OSX / Windows), download archive, extract it and run the binary.

For example you have a x64 Linux distribution.

  1. Log in to your server via ssh.

  2. Go to your home directory:

    cd ~
    
  3. Download PhantomJS binary:

    wget https://bitbucket.org/ariya/phantomjs/downloads/phantomjs-2.1.1-linux-x86_64.tar.bz2
    
  4. Extract archive:

    tar xvf phantomjs-2.1.1-linux-x86_64.tar.bz2

A new directory is created: phantomjs-2.1.1-linux-x86_64. The PhantomJS binary is phantomjs-2.1.1-linux-x86_64/bin/phantomjs. You can run it right now:

~/phantomjs-2.1.1-linux-x86_64/bin/phantomjs --version

2.1.1

(If it says "not found " instead that means you chose the wrong distribution, e.g. x64 instead of x32).

But this way of running it is inconvenient. It would be way better to be able to just type phantomjs script.js in any directory. To make it so add a link to a directory where binaries are kept by default:

sudo ln -s ~/phantomjs-2.1.1-linux-x86_64/bin/phantomjs /usr/bin/phantomjs

Then you can call PhantomJS from anywhere:

cd /var/www/
phantomjs --version

2.1.1

Vaviloff
  • 16,282
  • 6
  • 48
  • 56