User Tools

Site Tools


howto:languages

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Next revision
Previous revision
howto:languages [2023/07/29 11:09] – created tcmalhowto:languages [2024/02/23 11:05] (current) – tcmal
Line 1: Line 1:
-====== 3. Installing new languages ======+====== 5. Installing new packages ======
  
-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 [[https://asdf-vm.com/|asdf]] to manage the different languages and the different versions of those languages that we have installed.+If you want to run some code you wrote, you probably need some language or runtime to do so - eg Python, GCC, Haskell. It might happen to be installed system wide, but when it's not, we use a tool called [[https://nixos.org/|Nix]] to install packages per-user without having version conflicts.
  
-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.+Nix is able to do a lot more things, but for most cases you can use it like so:
  
-===== Installing asdf =====+<code> 
 +# install 'hello' from nixpkgs 
 +$ nix profile install nixpkgs#hello  
 +$ hello  
 +Hello, world! 
 +# it works!
  
-asdf gets installed per user, so you'll need to install it yourself.+# see everything installed for the current user 
 +$ nix profile list 
 +0 flake:nixpkgs#legacyPackages.x86_64-linux.hello github:NixOS/nixpkgs/98b00b6947a9214381112bdb6f89c25498db4959#legacyPackages.x86_64-linux.hello /nix/store/63l345l7dgcfz789w1y93j1540czafqh-hello-2.12.1
  
-First, download it with ''%%git clone https://github.com/asdf-vm/asdf.git ~/.asdf --branch v0.11.3%%''.+# uninstall 'hello'. note no 'nixpkgs.' this time 
 +$ nix profile remove 0 
 +removing 'flake:nixpkgs#legacyPackages.x86_64-linux.hello' 
 +</code>
  
-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.+To search for packages, go [[https://search.nixos.org/packages|here]]. 
  
-We can also get completions by doing ''%%echo '. "$HOME/.asdf/completions/asdf.bash"' >> ~/.bashrc%%''.+We're using a super small subset of what Nix can do here. It's also able to do things like per-project environments, building your projects, and generating docker images. For more info, see:
  
-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.+  * [[https://nixos.org/guides/how-nix-works.html|How Nix works]], the official explanation of the core concepts 
 +  * [[https://nix.dev/|nix.dev]] - tutorials and recipes for common tasks 
 +  * [[https://zero-to-nix.com/|Zero to Nix]], a more up-to-date but slightly incomplete resource
  
-===== Installing some plugins =====+===== Alternatives =====
  
-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.+The language versions that Nix can install might not be the ones you want, or it might be missing a package you need. In this case, you might want to try an alternative:
  
-You can see a full list of plugins [[here|https://github.com/asdf-vm/asdf-plugins]], but for now we're going to go ahead and try the python plugin.+  * Rust has [[https://rustup.rs/|rustup]] 
 +  * Node.JS has [[https://github.com/nvm-sh/nvm|NVM]] 
 +  * Ruby has [[https://github.com/rvm/rvm|RVM]] 
 +  * [[https://asdf-vm.com/|asdf]] supports many other languages 
 +  * You can just compile it from source and install it somewhere in your home directory.
  
-Install it with ''asdf plugin-add nodejs'' +If you're having problems, feel free to ask an admin.
- +
-===== 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.+
howto/languages.1690628970.txt.gz · Last modified: by tcmal