All Projects → isaacs → Nave

isaacs / Nave

Licence: isc
Virtual Environments for Node

Programming Languages

shell
77523 projects

Projects that are alternatives of or similar to Nave

nvm-auto-use.zsh
ZSH plugin to call `nvm use` automatically whenever you enter a directory that contains an `.nvmrc` file with a string telling nvm which node to use
Stars: ✭ 16 (-98.93%)
Mutual labels:  zsh, nvm
Nvm
nvm is a version manager for node.js, designed to be installed per-user, and invoked per-shell. nvm works on any POSIX-compliant shell (sh, dash, ksh, zsh, bash), in particular on these platforms: unix, macOS, and windows WSL.
Stars: ✭ 53,926 (+3507.09%)
Mutual labels:  zsh, nvm
Composure
Don't fear the Unix chainsaw
Stars: ✭ 272 (-81.81%)
Mutual labels:  versioning, zsh
Nvm Windows
A node.js version management utility for Windows. Ironically written in Go.
Stars: ✭ 18,587 (+1143.28%)
Mutual labels:  versioning, nvm
Zsh Nvm
Zsh plugin for installing, updating and loading nvm
Stars: ✭ 1,670 (+11.71%)
Mutual labels:  zsh, nvm
Nve
Run any command on specific Node.js versions
Stars: ✭ 531 (-64.48%)
Mutual labels:  versioning, nvm
Dotfiles
What tools and plugins I use for web development?
Stars: ✭ 73 (-95.12%)
Mutual labels:  zsh, nvm
.dot Config
📚 Example dot configs for tmux, tmuxp, vim, vcspull, i3 and awesome
Stars: ✭ 102 (-93.18%)
Mutual labels:  zsh
Ls colors
A collection of LS_COLORS definitions; needs your contribution!
Stars: ✭ 1,568 (+4.88%)
Mutual labels:  zsh
Violetear
Go HTTP router
Stars: ✭ 100 (-93.31%)
Mutual labels:  versioning
Robotics setup
Setup Ubuntu 18.04, 16.04 and 14.04 with machine learning and robotics software plus user configuration. Includes ceres tensorflow ros caffe vrep eigen cudnn and cuda plus many more.
Stars: ✭ 110 (-92.64%)
Mutual labels:  zsh
Forgit
💤 A utility tool powered by fzf for using git interactively.
Stars: ✭ 1,823 (+21.94%)
Mutual labels:  zsh
Dotfiles
Awesome personal dotfiles
Stars: ✭ 99 (-93.38%)
Mutual labels:  zsh
Nord Termite
An arctic, north-bluish clean and elegant Termite color theme.
Stars: ✭ 104 (-93.04%)
Mutual labels:  zsh
Json Git
A pure JS local Git to versionize any JSON
Stars: ✭ 109 (-92.71%)
Mutual labels:  versioning
Climate
The swiss-army knife of utility tools for Linux.
Stars: ✭ 1,372 (-8.23%)
Mutual labels:  zsh
Ubuntu On Steroids
Developer setup & configuration guide for Ubuntu.
Stars: ✭ 111 (-92.58%)
Mutual labels:  zsh
Zsh Snap
⚡️ Znap! A fast & light-weight plugin manager & Git repo manager for Zsh.
Stars: ✭ 98 (-93.44%)
Mutual labels:  zsh
Zsh Abbr
The zsh manager for auto-expanding abbreviations, inspired by fish shell.
Stars: ✭ 109 (-92.71%)
Mutual labels:  zsh
Fzf
🌸 A command-line fuzzy finder
Stars: ✭ 40,965 (+2640.13%)
Mutual labels:  zsh

nave

Virtual Environments for Node.

Switch out your node version and global npm install space in one command. Supports named environments. Uses subshells by default so that you can ^D or exit out of an environment quickly. No need to edit .bashrc or .profile, just install and go.

Installation

If you want a global nave command, you could install this thing with npm. But that's not really necessary. You can run the nave.sh shell script from here, or symlink it wherever you want.

with npm

If you have npm, presumably you already have Node, so it's a tiny bit silly, but maybe you like installing the top-level Node some other way, and install your subshell version switcher with npm. Why is a bash program in npm anyway? It's fine. Bits don't judge.

npm install -g nave

with basher

basher install isaacs/nave

Usage

To use a version of node, you do this:

nave use <some version>

If you want to name a virtual env, you can do this:

nave use <some name>

If that virtual env doesn't already exist, it'll prompt you to choose a version.

Both of these commands drop you into a subshell. Exit the shell with exit or ^D to go back from whence you came.

Here's the full usage statement:

Usage: nave <cmd>

Commands:

install <version>     Install the version specified (ex: 12.8.0)
install <name> <ver>  Install the version as a named env
use <version>         Enter a subshell where <version> is being used
use <ver> <program>   Enter a subshell, and run "<program>", then exit
use <name> <ver>      Create a named env, using the specified version.
                      If the name already exists, but the version differs,
                      then it will update the link.
usemain <version>     Install in /usr/local/bin (ie, use as your main nodejs)
clean <version>       Delete the source code for <version>
uninstall <version>   Delete the install for <version>
ls                    List versions currently installed
ls-remote             List remote node versions
ls-all                List remote and local node versions
latest                Show the most recent dist version
cache                 Clear or view the cache
help                  Output help information
auto                  Find a .naverc and then be in that env
auto <dir>            cd into <dir>, then find a .naverc, and be in that env
auto <dir> <cmd>      cd into <dir>, then find a .naverc, and run a command
                      in that env
get <variable>        Print out various nave config values.
exit                  Unset all the NAVE environs (use with 'exec')

Version Strings:
Any command that calls for a version can be provided any of the
following "version-ish" identifies:

- x.y.z       A specific SemVer tuple
- x.y         Major and minor version number
- x           Just a major version number
- lts         The most recent LTS (long-term support) node version
- lts/<name>  The latest in a named LTS set. (argon, boron, etc.)
- lts/*       Same as just "lts"
- latest      The most recent (non-LTS) version
- stable      Backwards-compatible alias for "lts".

To exit a nave subshell, type 'exit' or press ^D.
To run nave *without* a subshell, do 'exec nave use <version>'.
To clear the settings from a nave env, use 'exec nave exit'

Subshell-free operation

If you prefer to not enter a subshell, just run nave with exec

exec nave use lts/argon

You could even add something like this to your .bashrc file to save on typing:

n () {
  exec nave "$@"
}

Running shell script with specific version of Node.js

If there is need to run a shell script with version of node.js provided by nave following snippet can be inserted into script:

[ "${IN_SUBSHELL}" != "$0" ] && exec env IN_SUBSHELL="$0" nave use 5.0.0 bash "$0" "$@" || :

AUTOMAGICAL!

You can put a .naverc file in the root of your project (or anywhere). This file should contain the version that you want to use. It can be something like lts/boron or 6.8 or latest

echo lts/boron > ~/projects/my-project/.naverc

Then you can run nave auto to load the appropriate environment.

BUT THAT'S NOT NEARLY MAGICAL OR AUTO ENOUGH FOR ME THOUGH

If you want to get even more absurd/automated, put this in your bash settings (like ~/.bashrc or whatever)

alias cd='exec nave auto'

and then every time you cd into a different folder, it'll automatically load the correct nave settings, or exit nave-land if no automatic stuff could be found.

Note that doing this will also cause it to exit the nave environment when you cd to a directory that doesn't have a nave setting, so it can interfere with "normal" nave operation.

Also, aliasing cd is a very all-consuming type of change to make to one's system. You might wish to give it some other name, so that you can switch directories without affecting environment variables as a potentially surprising side effect, or even just run exec nave auto as an explicit action whenever you want this behavior to happen.

Bottom line, it's your shell, and I hope that this helps you enjoy it more :)

env vars

  • $NAVE The current shell. Either a version, or a name and version.
  • $NAVENAME The name of the current shell. Equal to $NAVEVERSION in unnammed environments.
  • $NAVEVERSION The version of node that the current shell is pointing to. (This should comply with node -v.)
  • $NAVELVL The level of nesting in the subshell.
  • $NAVE_DEBUG Set to 1 to run nave in bash -x style.
  • $NAVE_DIR Set to the location where you'd like nave to do its business. Defaults to ~/.nave.
  • $NAVE_CONFIG Set this to an array of arguments to pass to ./configure. Defaults to ("--debug"). (Note that parens are required to supply multiple arguments. I use ("--debug" "--without-npm") on my own system, since I'm usually using nave to test npm, so installing it in the subshell doesn't help much.) This can be set in the ~/.naverc file, or in your normal ~/.bash{rc,_profile} files.
  • $NAVE_JOBS If set, this will be the number of jobs to run when building node. If this isn't set, it'll use the $JOBS env, then try to guess a reasonable value based on the number of CPUs, then fall back on 2 if sysctl -n hw.ncpu fails.
  • $NAVE_SRC_ONLY Set to "1" to only build from source, rather than fetching binaries.

Compatibility

Prior to version 0.2, nave would run programs as node <program>. However, this is somewhat more limiting, so was dropped. If you prefer the old style, just prefix your command with node.

Nave requires bash. It will probably never work on Windows, or other systems lack a native Bourne Again Shell. Sorry.

Nave logins work with any shell, but executing a command in the nave environment (ie, nave use 12 node program.js) requires that your shell support the -c argument. (Bash, sh, zsh, and fish all work fine.)

Configuration

Nave will source ~/.naverc on initialization of a new subshell, if it exists and is readable.

You may control the place where nave puts things by setting the NAVE_DIR environment variable. However, note that this must be set somewhere other than ~/.naverc, since it needs to be set in the parent shell where the nave command is invoked.

By default, nave puts its stuff in ~/.nave/. If this directory does not exist and cannot be created, then it will attempt to use the location of the nave.sh bash script itself. If it cannot write to this location, then it will exit with an error.

Credits

nave borrows concepts, inspiration, and code from Tim Caswell's "nvm" and Kris Kowal's "sea" programs.

Sea is really nice, but is very tied to Narwhal. Also, it's a require.paths manager, which nave is not.

Nvm is also really nice, but has to be sourced rather than being run, and thus is a little bit wonky for some use cases. But it doesn't involve subshells, which makes it better for some others.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].