30

How do I install JSLint on Ubuntu?

I downloaded the source jsl-0.3.0-src.tar.gz from http://www.javascriptlint.com/download.htm and then extracted it to a dir called jsl-0.3.0 on my Desktop. I then moved it to /usr/local/bin which I have read is my PATH. I also want to mention that I have Rhino 1.7 installed already.

When I try to run jsl from terminal I got the following message:

No command 'jsl' found, did you mean:
 Command 'jls' from package 'sleuthkit' (universe)
 Command 'js' from package 'rhino' (main)
 Command 'sl' from package 'sl' (universe)
 Command 'fsl' from package 'fsl' (multiverse)
jsl: command not found

So I how do I properly install JSLint?

Eric Leschinski
  • 146,994
  • 96
  • 417
  • 335

4 Answers4

61

How to install JSLint on Ubuntu:

  1. Install nodejs (includes npm, the Node Package Manager):

    sudo apt-get install nodejs
    
  2. Install node-jslint. either globally:

    sudo npm install -g jslint
    

    or locally, and include it in $PATH:

    npm install jslint
    

    and add this line to your.bashrc (adjust version number as appropriate)

    alias jslint='~/.npm/jslint/0.1.8/package/bin/jslint.js'
    
Dan Dascalescu
  • 143,271
  • 52
  • 317
  • 404
gmunkhbaatarmn
  • 1,461
  • 2
  • 10
  • 20
  • this is perfect since I am currently learning node anyways but when I did `$ npm install -g jslint` I got an error which I posted in my question as an UPDATE. Will using `sudo` solve this? –  Jan 15 '12 at 21:17
  • 1
    if you when installing `npm` using this command: `sudo apt-get install npm`. Then you need to use with sudo: `sudo npm install -g jslint` – gmunkhbaatarmn Jan 16 '12 at 05:45
  • Looks like a simple solution, but when I run npm install, it only create a .node_module folder. I still can't run jslint in the shell. How are we suppose to have an executable file ? – FMaz008 Jan 18 '12 at 18:14
  • @FMaz008 add your node/bin path to $PATH in .bashrc – gmunkhbaatarmn Jan 19 '12 at 04:16
  • Instead of using package from repository download it from the main site (and possibly compile it). NPM is included with the latest versions. – Seppo Erviälä May 23 '12 at 17:24
  • @gmunkhbaatarmn why install `jslint` globablly? – scytale Jun 28 '12 at 14:44
  • @scytale because for command line usage jslint must be in /usr/local/bin/ folder. – gmunkhbaatarmn Jun 29 '12 at 00:36
  • This needs to be edited because npm is now included with node. – Myer Jul 16 '12 at 22:18
  • 1
    You probably want to put the alias in your ~/.bash_aliases file instead of your .bashrc. And you probably want the alias to be jsl= – boatcoder Sep 20 '13 at 17:20
  • @PeterNore: how about just going ahead and editing the answer next time, instead of complaining that it needs to be edited? Note: I've edited it myself. – Dan Dascalescu Feb 18 '14 at 13:37
19

Here are the instructions I followed to have jslint working on Ubuntu 10.10/Vim 7.3 (and Mac OS X).

EDIT

So, I've just spotted a mistake in the given link. Here are the correct steps (assuming you have already downloaded and unpacked the archive to your desktop:

$ cd /path/to/jsl-0.3.0/src
$ make -f Makefile.ref
$ cp Linux_All_DBG.OBJ/jsl /usr/local/bin/jsl

At that point you can open a new terminal window and type $ jsl to display a quick help or invoke it from Vim or directly on a file in the terminal.

END EDIT

  • /usr/local/bin is not your "PATH", it's only one of the many directories that can be part your PATH environment variable. $ echo $PATH will tell you what these directories are and thus where you can put the jsl executable. You can also put it in another place and add an alias to your .bashrc.

  • Why do you expect to be able to run jslint from rhino?

romainl
  • 186,200
  • 21
  • 280
  • 313
  • when i do `echo $PATH` I see a list of paths separated by colons. `/usr/local/bin` is among them though. So what I did was make a `jsl` dir in `/usr/local/bin/` and then drop in the entire `jsl-0.3.0` folder which contains `jsl`. So the entire path to `jsl` is `/usr/local/bin/jsl/jsl-0.3.0/src/Linux_All_DBG.OBJ`. When I type `jsl` I just get the same `jsl: command not found` error I mentioned in my post. thanks so far though. –  Jan 15 '12 at 16:51
  • You have to **build** `jsl` first and _then_ make the resulting executable accessible system wide. There is an error there, though. I'll edit my answer. – romainl Jan 15 '12 at 17:42
2

You said you just copied the source to /usr/local/bin. You need to compile it. Follow the build instructions in the README.html

Unix

  • Use 'gmake -f Makefile.ref' to build. To compile optimized code, pass BUILD_OPT=1 on the gmake command line or preset it in the environment or Makefile.ref. NOTE: Do not attempt to use Makefile to build the standalone JavaScript engine. This file is used only for building the JS-engine in the Mozilla browser.
  • Each platform on which JS is built must have a *.mk configuration file in the js/src/config directory. The configuration file specifies the compiler/linker to be used and allows for customization of command-line options. To date, the build system has been tested on Solaris, AIX, HP/UX, OSF, IRIX, x86 Linux and Windows NT.
  • Most platforms will work with either the vendor compiler or gcc. (Except that HP builds only work using the native compiler. gcc won't link correctly with shared libraries on that platform. If someone knows a way to fix this, let us know.)
  • If you define JS_LIVECONNECT, gmake will descend into the liveconnect directory and build LiveConnect after building the JS engine.
  • To build a binary drop (a zip'ed up file of headers, libraries, binaries), check out mozilla/config and mozilla/nsprpub/config. Use 'gmake -f Makefile.ref nsinstall-target all export ship'

As for your question about the difference. It says on the download page that one is written in JavaScript itself.

We all stand on the shoulders of giants. I would like to especially acknowledge Douglas > Crockford's work on JSLint. This lint is itself written in JavaScript and is an interesting and rather sophisticated script. Crockford's ideas about good coding practices served as a springboard for many of these lint rules.

Drew Chapin
  • 7,779
  • 5
  • 58
  • 84
  • Ubuntu does not have `gmake` so I used `make` which is the same thing. It ended with out any errors so I assume it got built fine but I still can not run JSLint by typing the `jsl` command in terminal or by running `rhino` (or `js`) and typing `jslint`. If I try the latter, I get `Error: "jslint" is not defined.`. –  Jan 14 '12 at 19:44
  • Usually, you need to type `make install` afterwards to copy the binary and necessary files to your bin directory. Did typing `make` produce a `jsl` binary in the source directory? – Drew Chapin Jan 15 '12 at 08:10
  • after doing `make -f Makefile.ref` a dir called `Linux_All_DBG.OBJ` was created which contained a file called `jsl` and another called `jsl.o` which were among many other files. Also, `make install` did not work in the `src` or `Linux_All_DBG.OBJ` dirs. I got the error `make: *** No rule to make target `install'. Stop.` –  Jan 15 '12 at 16:35
  • change directories in to `Linux_All_DBG.OBJ` and type `./jsl`, if this does what you want then move that file to `/usr/local/bin` – Drew Chapin Jan 15 '12 at 19:07
  • Ok I moved `jsl` file to `/usr/local/bin/` and now when I type `jsl` from anywhere on my system, it runs fine. Thanks but what should I do with the `js-0.3.0` directory where the `Linux_All_DBG.OBJ` dir is? –  Jan 15 '12 at 22:09
  • It should be safe to delete it. – Drew Chapin Jan 16 '12 at 00:34
1

Look at your "jsl-0.3.0/src/README.html" file. This says:

1) You have a "source package". You need to "build" it (with a C compiler), then install your build.

2) This is more than just JSLint. It's an entire Javascript engine. Per the README:

This is the README file for the JavaScript Reference (JSRef, now better known as SpiderMonkey) implementation. It consists of build conventions and instructions, source code conventions, a design walk-through, and a brief file-by-file description of the source.

JSRef builds a library or DLL containing the JavaScript runtime (compiler, interpreter, decompiler, garbage collector, atom manager, standard classes). It then compiles a small "shell" program and links that with the library to make an interpreter that can be used interactively and with test .js files to run scripts. The code has no dependencies on the rest of the Mozilla codebase.

3) Here is Douglas Crockford's original JSLint page:

http://www.jslint.com/

4) And here is a a good example of how you might use JSLint locally, on your own PC:

http://code.google.com/p/js-ria-tools/wiki/JSLint

5) You say you already have Rhino - good. In Google, you'll find many obsolete links to www.jslint.com/rhino. Here's why - along with links to current Rhino-related info:

http://hustoknow.blogspot.com/2011/02/jslint-and-rhino-support.html

'Hope that helps!

paulsm4
  • 114,292
  • 17
  • 138
  • 190
  • Thanks. I built the source via `make -f Makefile.ref` which flew by with out any errors as far as I could tell but still I can not use `jslint` when in the JS interpreter (which is invoked via `js` or `rhino`). Also running `jsl` still does not work from terminal. Any ideas? –  Jan 14 '12 at 19:48