Local Volta Setup
The volta javascript tool manager installs user-wide per default by modifying shell settings. A confined per-project installation just requires a few variables.
The recommended installation method for volta is the controversial curl|bash
idiom.
By default, this installs in the user’s home folder and directly calls volta setup.
This setup procedure in turn either creates or modifies shell profiles in-place – an approach that can be seen problematic.
In addition, the setup tries to permanently put it in front of the $PATH
variable, thereby always possibly intercepting all commands.
This can lead to subtle issues as it hardly allows to have multiple projects with mixed or non-volta dependencies.
Also, user dotfiles might be under version control or automatically deployed, reverting changes at any time.
The workaround is rather straight-forward, though. For a per-project volta installation:
- set
$VOLTA_HOME
to bootstrap an arbitrary local directory instead - pass
--skip-setup
to avoid manipulating or creating global shell configuration
For a local volta activation:
- set
$VOLTA_HOME
to use it for the shims, configuration, and downloaded images - set
$VOLTA_HOME/bin
as the foremost$PATH
folder to be searched for binaries
Corresponding commands to automate this process could look like the following, shown here as Makefile:
.PHONY: volta clean
volta: .volta/setup
.volta:
@mkdir -p $(@)
curl -o $(@)/get.volta.sh https://get.volta.sh
VOLTA_HOME=$(@) bash $(@)/get.volta.sh --skip-setup
.volta/setup: .volta
echo 'export VOLTA_HOME="$(CURDIR)/.volta"' > $(@)
echo 'export PATH="$${VOLTA_HOME}/bin:$${PATH}"' >> $(@)
echo 'export PS1="⚡$${PS1}"' >> $(@)
clean:
rm -rf .volta
Similar to a Python virtual environment, this will create an activation script that just needs to be sourced for enabling the local installation.
. .volta/setup
All following calls to node
, npm
, yarn
and the like will be under volta’s control for the lifetime of the current shell as usual.