Blog

nodejs-logo

NOTE: This post refers to Node v0.6.19. For new v0.8.0 please visit this.

On Node.js website I read:

Node.js is a platform built on Chrome’s JavaScript runtime for easily building fast, scalable network applications. Node.js uses an event-driven, non-blocking I/O model that makes it lightweight and efficient, perfect for data-intensive real-time applications that run across distributed devices.


Awesome! Now I want to install Node on my Fox Board G20, my preferred ARM based SBC!
To do this I want the latest version of Node, but from Acmesystems website I can download only an older version. No problem: if you want as me the latest Node on your Fox Board G20, read below and you can.

  1. Step 1: enable swap

    By default Fox Board has his swap disabled, but to complete all tasks to install node.js it must be enabled; open your terminal and type:

    debarm:~$ nano /etc/fstab
    #Mount the fat16 partition where is located
    #the Kernel image
    /dev/mmcblk0p1 /media/mmc_p1 vfat noatime 0 1
    
    #Mount the rootfs partition
    /dev/mmcblk0p2 / ext4 noatime 0 1
    
    #Mount the data partition
    /dev/mmcblk0p3 /media/data ext4 noatime 0 1
    
    #Enable the swap memory
    #/dev/mmcblk0p4 none swap sw 0 0
    
    proc /proc proc none 0 0

    uncomment the line #12:

    #Mount the fat16 partition where is located
    #the Kernel image
    /dev/mmcblk0p1 /media/mmc_p1 vfat noatime 0 1
    
    #Mount the rootfs partition
    /dev/mmcblk0p2 / ext4 noatime 0 1
    
    #Mount the data partition
    /dev/mmcblk0p3 /media/data ext4 noatime 0 1
    
    #Enable the swap memory
    /dev/mmcblk0p4 none swap sw 0 0
    
    proc /proc proc none 0 0[/sourcecode]
    

    save and exit and reboot your Fox Board.

  2. Step 2: install prerequisites

    To install all prerequisites simply type:

    debarm:~$ aptitude update
    debarm:~$ aptitude install git-core curl build-essential openssl libssl-dev python libcurl4-openssl-dev
  3. Step 3: install nvm

    The most simple method to install latest Node is using nvm (Node Version Manager) hosted on Github.
    Get nvm from Github:

    debarm:~$ git clone git://github.com/creationix/nvm.git ~/nvm
  4. Step 4: customize nvm

    Unfortunately using the default nvm isn’t possible to compile Node due to ARM type used on Fox Board. Typing:

    debarm:~$ cat /proc/cpuinfo

    you see:

    Processor	: ARM926EJ-S rev 5 (v5l)
    BogoMIPS	: 197.83
    Features	: swp half thumb fastmult edsp java 
    CPU implementer	: 0x41
    CPU architecture: 5TEJ
    CPU variant	: 0x0
    CPU part	: 0x926
    CPU revision	: 5
    
    Hardware	: Acme Systems srl FOX Board G20
    Revision	: 0000
    Serial		: 0000000000000000
    

    therefore gcc must be use right CPU architecture and vfp feature isn’t present. To avoid this problem you must customize nvm script:

    debarm:~$ nano ~/nvm/nvm.sh
    case $1 in
        "help" )
          echo
          echo "Node Version Manager"
          echo
          echo "Usage:"
          echo "    nvm help                    Show this message"
          echo "    nvm install [-s] <version>  Download and install a <version>"
          echo "    nvm uninstall <version>     Uninstall a version"
          echo "    nvm use <version>           Modify PATH to use <version>"
          echo "    nvm run <version> [<args>]  Run <version> with <args> as arguments"
          echo "    nvm ls                      List installed versions"
          echo "    nvm ls <version>            List versions matching a given description"
          echo "    nvm ls-remote               List remote versions available for install"
          echo "    nvm deactivate              Undo effects of NVM on current shell"
          echo "    nvm alias [<pattern>]       Show all aliases beginning with <pattern>"
          echo "    nvm alias <name> <version>  Set an alias named <name> pointing to <version>"
          echo "    nvm unalias <name>          Deletes the alias named <name>"
          echo "    nvm copy-packages <version> Install global NPM packages contained in <version> to current version"
          echo
          echo "Example:"
          echo "    nvm install v0.4.12         Install a specific version number"
          echo "    nvm use 0.2                 Use the latest available 0.2.x release"
          echo "    nvm run 0.4.12 myApp.js     Run myApp.js using node v0.4.12"
          echo "    nvm alias default 0.4       Auto use the latest installed v0.4.x version"
          echo
        ;;
    
        "install" )
          # initialize local variables
          if [ ! `which curl` ]; then
            echo 'NVM Needs curl to proceed.' >&2;
          fi
    

    Edit code as below:

      case $1 in
        "help" )
          echo
          echo "Node Version Manager"
          echo
          echo "Usage:"
          echo "    nvm help                    Show this message"
          echo "    nvm download <version>      Download only a <version>"
          echo "    nvm foxinstall <version>    Install a <version> in Fox Board G20"
          echo "    nvm install <version>       Download and install a <version>"
          echo "    nvm uninstall <version>     Uninstall a version"
          echo "    nvm use <version>           Modify PATH to use <version>"
          echo "    nvm run <version> [<args>]  Run <version> with <args> as arguments"
          echo "    nvm ls                      List installed versions"
          echo "    nvm ls <version>            List versions matching a given description"
          echo "    nvm deactivate              Undo effects of NVM on current shell"
          echo "    nvm alias [<pattern>]       Show all aliases beginning with <pattern>"
          echo "    nvm alias <name> <version>  Set an alias named <name> pointing to <version>"
          echo "    nvm unalias <name>          Deletes the alias named <name>"
          echo "    nvm copy-packages <version> Install global NPM packages contained in <version> to current version"
          echo
          echo "Example:"
          echo "    nvm install v0.4.12         Install a specific version number"
          echo "    nvm use 0.2                 Use the latest available 0.2.x release"
          echo "    nvm run 0.4.12 myApp.js     Run myApp.js using node v0.4.12"
          echo "    nvm alias default 0.4       Auto use the latest installed v0.4.x version"
          echo
        ;;
            "download" )
              if [ ! `which curl` ]; then
                echo 'NVM Needs curl to proceed.' >&2;
              fi
     
              if [ $# -ne 2 ]; then
                nvm help
                return
              fi
              VERSION=`nvm_version $2`
     
              [ -d "$NVM_DIR/$VERSION" ] && echo "$VERSION is already installed." && return
     
              tarball=''
              if [ "`curl -Is "http://nodejs.org/dist/$VERSION/node-$VERSION.tar.gz" | grep '200 OK'`" != '' ]; then
                tarball="http://nodejs.org/dist/$VERSION/node-$VERSION.tar.gz"
              elif [ "`curl -Is "http://nodejs.org/dist/node-$VERSION.tar.gz" | grep '200 OK'`" != '' ]; then
                tarball="http://nodejs.org/dist/node-$VERSION.tar.gz"
              fi
              if (
                [ ! -z $tarball ] && \
                mkdir -p "$NVM_DIR/src" && \
                cd "$NVM_DIR/src" && \
                curl -C - --progress-bar $tarball -o "node-$VERSION.tar.gz" && \
                tar -xzf "node-$VERSION.tar.gz" && \
                cd "node-$VERSION"
                )
              then
                echo "nvm: please customize $NVM_DIR/src/node-$VERSION/deps/v8/SConstruct"
              else
                echo "nvm: download $VERSION failed!"
              fi
            ;;
            "foxinstall" )
              if [ $# -ne 2 ]; then
                nvm help
                return
              fi
              VERSION=`nvm_version $2`
     
              [ -d "$NVM_DIR/$VERSION" ] && echo "$VERSION is already installed." && return
     
              if (
                cd "$NVM_DIR/src/node-$VERSION" && \
                ./configure --prefix="$NVM_DIR/$VERSION" && \
                make && \
                rm -f "$NVM_DIR/$VERSION" 2>/dev/null && \
                make install
                )
              then
                nvm use $VERSION
                if ! which npm ; then
                  echo "Installing npm..."
                  if [[ "`expr match $VERSION '\(^v0\.1\.\)'`" != '' ]]; then
                    echo "npm requires node v0.2.3 or higher"
                  elif [[ "`expr match $VERSION '\(^v0\.2\.\)'`" != '' ]]; then
                    if [[ "`expr match $VERSION '\(^v0\.2\.[0-2]$\)'`" != '' ]]; then
                      echo "npm requires node v0.2.3 or higher"
                    else
                      curl http://npmjs.org/install.sh | clean=yes npm_install=0.2.19 sh
                    fi
                  else
                    curl http://npmjs.org/install.sh | clean=yes sh
                  fi
                fi
              else
                echo "nvm: install $VERSION failed!"
              fi
            ;;    
        "install" )
          if [ ! `which curl` ]; then
            echo 'NVM Needs curl to proceed.' >&2;
          fi
    

    Save nvm.sh file and activate your nvm:

    debarm:~$ . ~/nvm/nvm.sh
    
  5. Step 5: download Node source code

    To download Node source code simply use customized nvm:

    debarm:~$ nvm download v0.6.19
    
  6. Step 6: customize SConstruct file

    After a while you have the Node source code and you must customize the v8 script:

    debarm:~$ nano ~/nvm/src/node-v0.6.19/deps/v8/SConstruct
    
      'gcc': {
        'all': {
          'CCFLAGS':      ['$DIALECTFLAGS', '$WARNINGFLAGS'],
          'CXXFLAGS':     ['-fno-rtti', '-fno-exceptions'],
        },
        'visibility:hidden': {
          # Use visibility=default to disable this.
          'CXXFLAGS':     ['-fvisibility=hidden']
        },
    

    and modify as follow:

      'gcc': {
        'all': {
          'CCFLAGS':      ['$DIALECTFLAGS', '$WARNINGFLAGS', '-march=armv5te'],
          'CXXFLAGS':     ['-fno-rtti', '-fno-exceptions', '-march=armv5te'],
        },
        'visibility:hidden': {
          # Use visibility=default to disable this.
          'CXXFLAGS':     ['-fvisibility=hidden']
        },
    

    and finally

          'armeabi:softfp' : {
            'CPPDEFINES' : ['USE_EABI_HARDFLOAT=0'],
            'vfp3:on': {
              'CPPDEFINES' : ['CAN_USE_VFP_INSTRUCTIONS']
            },
            'simulator:none': {
              'CCFLAGS':     ['-mfloat-abi=softfp'],
            }
          },
    

    in

          'armeabi:softfp' : {
            'CPPDEFINES' : ['USE_EABI_HARDFLOAT=0']
            #'vfp3:on': {
            #  'CPPDEFINES' : ['CAN_USE_VFP_INSTRUCTIONS']
            #},
            #'simulator:none': {
            #  'CCFLAGS':     ['-mfloat-abi=softfp'],
            #}
          },
    
  7. Step 7: install Node

    Now use again nvm:

    debarm:~$ nvm foxinstall v0.6.19
    

    After a few hours (be patient!) you have compiled the latest Node version and you must use it:

    debarm:~$ nvm use v0.6.19
    

    Done! Now you can verify all:

    debarm:~$ node -v
    debarm:~$ npm -v
    

    If all versions appear, you can install your desired Node packages using npm as you know:

    debarm:~$ npm install express
    

    You can also set the default Node version as follow:

    debarm:~$ nvm alias default v0.6.19
    

Good programming with Node!


 ,  ,

About Marcello Gesmundo

I'm the founder of Yoovant company. I'm an engineer and an artist: what could be better than combine the technologies with the arts?

7 Comment(s)
  1. maadaf August 20, 2013 at 16:49

    Hi Marcello,
    Thank you for your step by step guide.
    I’m really a newbie on Aria G25 and on Linux embedded.
    I’m trying to install Node.1.10 but when I enter the command ‘aptitude update’ it gave me some errors and later I can’t run the nsm.sh.

    W: GPG error: http://packages.dotdeb.org stable Release: The following signatures couldn’t be verified because the public key is not available: NO_PUBKEY E9C74FEEA2098A6E
    W: Failed to fetch http://packages.dotdeb.org/dists/stable/all/binary-armel/Packages: 404 Not Found
    E: Some index files failed to download. They have been ignored, or old ones used instead.
    E: Couldn’t rebuild package cache

    Thank you in advance
    maadaf

    • Marcello Gesmundo August 20, 2013 at 19:06

      Hi Maadaf,

      your error message is about a non recognized repository: http://packages.dotdeb.org. If you really want to use this instead the standard repository, type:

      root@debarm:~# gpg --keyserver pgpkeys.mit.edu --recv-key E9C74FEEA2098A6E
      root@debarm:~# gpg -a --export E9C74FEEA2098A6E | apt-key add -

      and next try to use aptitude.

      Best regards,

      Marcello

      • maadaf August 22, 2013 at 10:58

        Hi Marcello,

        You were right. I remove that repository and now it works fine.

        Thanks

        Maddaf

  2. Arturo September 12, 2013 at 14:04

    Hi,
    I try to install and when I launch make, I receive following message:

    /root/nvm/src/node-v0.6.19/deps/v8/src/arm/macro-assembler-arm.cc:64:3: error: #error “For thumb inter-working we require an architecture which supports blx”
    scons: *** [obj/release/arm/macro-assembler-arm.o] Error 1
    scons: building terminated because of errors.
    Waf: Leaving directory `/root/nvm/src/node-v0.6.19/out’
    Build failed: -> task failed (err #2):
    {task: libv8.a SConstruct -> libv8.a}
    make: *** [program] Error 1
    What do you think about?

    Many thanks.

    Arturo

    • Marcello Gesmundo September 12, 2013 at 15:41

      Hi Arturo,

      please see the step 5. You can also install the new 0.10x following my newly post.

      Regards,

      Marcello

      • Arturo September 13, 2013 at 10:26

        It’ works now! Great guide!

        Many thanks.

        Arturo

Leave a Reply to Marcello Gesmundo Cancel reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>