centos使用ruby gem安装 libv8,安装v8js

转自:http://appsintheopen.com/posts/18-installing-the-libv8-ruby-gem-on-centos-5-8

 

首先安装 ruby gem 

yum install -y ruby 

 

First, Centos 5.8 ships with gcc 4.1.4, but to compile libv8 you need 4.4. Luckily, this step is easy:

 
  1. $ yum install gcc44-c++

Next, you need to tell the build to make use of it. The easiest thing to do here, is to export a couple of environment variables:

 
  1. $ export CC=/usr/bin/gcc44
  2. $ export CXX=/usr/bin/g++44

Now if you attempt gem install libv8, you will get an error along the lines of:

 
  1. $ gem install libv8
  2. creating MakefileUsing compiler:/usr/bin/g++44Traceback(most recent call last):File"build/gyp/gyp", line 15,in?import gyp
  3. File"build/gyp/pylib/gyp/__init__.py", line 8,in?import gyp.input
  4. File"build/gyp/pylib/gyp/input.py", line 14,in?import gyp.common
  5. File"build/gyp/pylib/gyp/common.py", line 375with open(source_path)as source_file:^SyntaxError: invalid syntax
  6. gmake:***[out/Makefile.x64]Error1
  7. GYP_GENERATORS=make \
  8. build/gyp/gyp --generator-output="out" build/all.gyp \
  9. -Ibuild/standalone.gypi --depth=. \
  10. -Dv8_target_arch=x64 \
  11. -S.x64 -Dhost_arch=x64

This is because the version of Python that is shipped with Centos is too old. Upgrading Python is not too hard, but be warned - do not under any circumstance replace the shipped Centos Python - lots of stuff depends on it, and it you replace it, lots of stuff will break.

To install Python 2.7:

 
  1. $ yum install bzip2
  2. $ yum install bzip2-devel
  3. $ wget http://www.python.org/ftp/python/2.7.3/Python-2.7.3.tgz
  4. $ tar -xf Python-2.7.3.tgz
  5. $ cd Python-2.7.3
  6. $ ./configure
  7. $ make
  8. $ make altinstall

The final step is very important - this stops it overwriting the default Centos Python. We are on the home straight now. To get the libv8 install to use Python 2.7 instead of Python 2.4, I thought I could create a symlink in my local directory, and then slip my local directory onto the front of my path:

 
  1. $ ln -s /usr/local/bin/python2.7 python
  2. $ export PATH=.:$PATH
  3. $ python --version
  4. Python2.7.3

However, that didn't work.

I don't know why - maybe the Makefile explicitly references /usr/bin/python? What I did was move the existing Python executable out of the way, and symlink the Python 2.7 in its place:

 
  1. $ mv /usr/bin/python /usr/bin/python_
  2. $ ln -s /usr/local/bin/python2.7/usr/bin/python

使用gem安装 libv8

 
  1. $ gem install libv8
  2. ( about 5 minutes later)Buildingnative extensions.This could take a while...Successfully installed libv8-3.11.8.41 gem installed
  3. Installing ri documentation for libv8-3.11.8.4...InstallingRDoc documentation for libv8-3.11.8.4...

Now remember, to put Python back the way you found it:

  1. $ rm /usr/bin/python
  2. $ mv /usr/bin/python_ /usr/bin/python

 

最后安装 v8js

Compile V8 5.6 and newer (using GN)

# Install required dependencies
sudo apt-get install build-essential curl git python libglib2.0-dev

cd /tmp

# Install depot_tools first (needed for source checkout)
git clone https://chromium.googlesource.com/chromium/tools/depot_tools.git

#vi /etc/profile 添加一行
export PATH=`pwd`/depot_tools:"$PATH"
#source /etc/profile 使环境变量生效

# Download v8
fetch v8
cd v8

# (optional) If you'd like to build a certain version:
git checkout 6.4.388.18
gclient sync

# Setup GN
tools/dev/v8gen.py -vv x64.release -- is_component_build=true

# Build
ninja -C out.gn/x64.release/

# Install to /opt/v8/
sudo mkdir -p /opt/v8/{lib,include}
sudo cp out.gn/x64.release/lib*.so out.gn/x64.release/*_blob.bin \
  out.gn/x64.release/icudtl.dat /opt/v8/lib/
sudo cp -R include/* /opt/v8/include/

On Debian Stretch you need to set RPATH on the installed libraries, so the library loader finds the dependencies:

sudo apt-get install patchelf
for A in /opt/v8/lib/*.so; do sudo patchelf --set-rpath '$ORIGIN' $A; done

Compile php-v8js itself

cd /tmp
git clone https://github.com/phpv8/v8js.git
cd v8js
phpize
./configure --with-v8js=/opt/v8 LDFLAGS="-lstdc++"
make
make test
sudo make install

Then add extension=v8js.so to your php.ini file. If you have a separate configuration for CLI, add it there also.

V8Js' build system assumes that the icudtl.dat file is located next to the libv8.so library file and compiles the path into the library itself. If for whatever reason the icudtl.dat file is stored at a different place during runtime, you need to set the php.ini variable v8js.icudtl_dat_path to point to the file. Otherwise locale-aware features of V8 will not work as expected.

 

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值