User Tools

Site Tools


tutorials:3

This is an old revision of the document!


3. Installing new languages

If you want to run some code you wrote, you probably need some language or runtime to do so - eg Python, GCC, Haskell. We'll use a tool called asdf to manage the different languages and the different versions of those languages that we have installed.

This lets us use older versions when we need to, and means you don't have to wait for an admin to install something for you.

Installing asdf

asdf gets installed per user, so you'll need to install it yourself.

First, download it with git clone https://github.com/asdf-vm/asdf.git ~/.asdf --branch v0.11.3.

Then, make sure we load it whenever we login by doing echo '. "$HOME/.asdf/asdf.sh"' >> ~/.bashrc. This appends . $HOME/.asdf/asdf.sh to our bashrc, which is run whenever we login. That line itself adds all the variables and declarations from asdf to our current environment.

We can also get completions by doing echo '. "$HOME/.asdf/completions/asdf.bash"' >> ~/.bashrc.

Now we can load it in our current session by doing . ~/.bashrc to reload everything in bashrc. Test it out by running asdf - you should see a list of commands pop up.

Installing some plugins

To deal with all the different languages you might want to install, asdf uses a /plugin/ for each of them. Once you've installed each plugin, you'll run the same asdf commands, but just change the plugin name for each of them.

You can see a full list of plugins https://github.com/asdf-vm/asdf-plugins, but for now we're going to go ahead and try the python plugin.

Install it with asdf plugin-add nodejs

Installing NodeJS

Now we have the nodejs plugin, we can list all the versions with asdf list all nodejs (it will have a lot of output).

To try it out, let's install a specific version of Nodejs - run asdf install nodejs 19.8.1.

If you try to run node –version, you'll see it still comes up with an error. This is because we haven't yet told asdf that we want to use this specific version. Let's tell asdf we want to use it as a global default - asdf global nodejs 19.8.1. Now, if you run node –version, you'll see we have the exact right version!

Local overrides

We set nodejs as a global default in the previous step, but suppose we have one project that runs an old version and one that needs a newer one.

For this, we can use local overrides. If you run asdf local <plugin> <version, then you will 'pin' that tool to a specific version in your current directory and any child ones. This also creates a .tool-version file which you can commit to Git, so if you use asdf on other computers it will ensure you have the right version.

tutorials/3.1680525089.txt.gz · Last modified: 2023/04/03 12:31 by tcmal