Many developers like to sandbox their stuff with things like Docker, which I’m not a fan of, it just feels like a clumsy way of doing it, but fortunately there is a way to do with shell script alone. I have many different example of shell script to do that for Golang, Node and Deno.
I’m assuming you got the SDK in ~/.software/sdk
and the bin path ~/.software/bin
in PATH environment variable for
the shell script.
Golang
#!/bin/dash
PATH="/Users/cjjackson/.software/sdk/$(basename $0)/bin:$PATH"
go $@
Notice the path reflect the file name of the script at $(basename $0)
Node
#!/bin/dash
PATH="/Users/cjjackson/.software/sdk/$(basename $0)/bin:$PATH"
if [ $1 = "--" ]
then
shift 1
$@
else
node $@
fi
If you want to run rpm, you have to run the command like node16 -- npm install
Deno
#!/bin/dash
PATH="/Users/cjjackson/.software/sdk/$(basename $0)/bin:$PATH"
deno $@
Conclusion
You can create copies of the script for different version of the SDK without having to rely on Docker or any gimmick in the wild, which would be probably over engineered compared to those script. It not limited to those SDK I mentioned, can be used with other SDK.
The trick was prepending the PATH environment variable temporarily, the same trick that used by Jetbrain’s IDE suite, I
should know I run echo $PATH
inside the IDE terminal and it did prepend something in the beginning.
Also you might want to adjust the PATH variable for your environment, stick to hard coding user home directory otherwise
it won’t work with sudo
.