Goodbye, Nodever! Hello, update-alternatives!
Mark Irish guest blogs about the details and benefits of this transition.
By Mark Irish05/14/2020
In a recent update, though, nodever has been replaced with a more powerful utility. Mark Irish, a member of IBM’s open source team in Rochester, guest blogs about the details and benefits of this transition.
IBM i has just become a little more normal, as a popular Linux®tool has now arrived on the system: update-alternatives. update-alternatives maintains symbolic links for various “alternatives” of packages, allowing multiple versions to exist on a system that can be swapped in as the system default at any time. Originally implemented by Debian Linux, update-alternatives is now widely used by many operating systems, and that now includes IBM i!
The biggest immediate change for open-source packages on IBM i is that update-alternatives is replacing nodever for managing Node.js installations. That’s right, nodever is going away (eventually). In many ways, nodever was little more than a custom script written specifically for Node.js on IBM i that mimicked the more generic functionality of update-alternatives. Now that update-alternatives has been ported to PASE, there is no longer a compelling reason for nodever to exist, and it has become deprecated.
Worried that the upgrade process is going to be a huge headache? Concerned that you will have to learn a whole new set of commands to change the system version of Node.js? Well don’t be! We have tried to make the transition as painless as possible, from making the upgrade to update-alternatives automatic when you download an update for Node.js, to giving you instructions on how to use update-alternatives if you call nodever after the upgrade.
Converting from nodever to update-alternatives
To begin using update-alternatives with Node.js, you simply need to download the latest version of your desired major release (or, if you don’t want to touch your Node.js versions, just download nodever 1.0.0). nodever will then run a script to convert the old nodever setupto the more standard update-alternatives system. After the upgrade, you never have to use nodever again, and can safely remove it from your system.
If you want to continue to use nodever, you can still call it with the same commands that you have used previously: Just known that under the covers, it will be calling update-alternatives itself (and telling you what commands it is running, while strongly suggesting you use them yourself). As nodever is now deprecated, it is no longer receiving updates, so it is best to call update-alternatives directly as soon as you are comfortable with the commands.
Like nodever, update-alternatives supports two modes of operation: auto and manual.
In auto mode, the system-wide version will always point at the version that has the highest priority.When you convert from nodever to using update-alternatives, each major Node.js version it is registered with a priority equal to its major version number. That means that Node.js 10 will have a priority of 10, while Node.js 12 will have a priority of 12, and so forth. When you are auto mode, it will select the highest version of Node.js you have installed on your system.
In manual mode, the system-wide version will not change unless specifically asked to or the current version is uninstalled. If you have nodever on your system when you upgrade, the update-alternatives Node.js group will be set tomanual mode, with the active link pointing tothe version previously set by nodever.Thus, everything will work just as it did before the upgrade, and only the underlying mechanism for managing links has changed.
However, ifyou have neverinstalled nodever (which means you never installed Node.js), update-alternatives will be in automatic mode from the start. This means if you install a newer version of Node.js (maybe to play around with or do some QA testing), it willchange the default version unless you specifically set update-alternatives in to manual mode.
The most important takeaways are that upgrading to use update-alternatives happens automatically when you update Node.js or nodever, and nothing should break in the upgrade process from nodever to update-alternatives. Whatever version of Node.js you had as your active link before the upgrade process will remain the active link after the upgrade process. If you are really afraid of change, you can still call nodever with the same commands you are used to, it will just have slightly different output to the terminal letting you know that it is using update-alternatives under the covers (and suggesting you cut out the middleman in the future). If you weren’t an observant system administrator or developer (and didn’t read this blog), you might not even realize that anything had changed!
Using update-alternativesAlthough you can technically continue to use nodever, you should really start to call update-alternatives directly. This short tutorial covers all of the update-alternatives to accomplish everything you could do with nodever.
`alternatives --auto node`
Like `nodever auto`, this command sets the group to auto mode, after which time the active link will point to the highest major version of Node.js installed on the system. To set a link group back to manual mode, call either `--config` or `--set` as outlined below.
alternatives --config node`
Like `nodever list`, this command will provide an interactive configuration menu that allows you to visually see all the available paths for a link group and easily select which one you want. This will also set your link group into manual mode. Used with the `node` link group, you will see all versions of Node.js currently installed on the system, and the link will be updated to whichever one you choose.
`alternatives set node /QOpenSys/pkgs/lib/nodejs12/bin/node`
Like `nodever`, this command will change which path the link is pointing to, and set the group into manual mode. To find the valid paths, you can call `alternatives --display node`. `alternatives --set` is a little more complex than `alternatives --config node`, so you should probably favor that command unless you have a good reason not to.
And that’s it! With these three commands you can interact with your Node.js binaries the same way you would with nodever, but now your skills will transfer to all packages that use update-alternatives in the future. As a final note, keep in mind that you should never have to worry about installing or removing links and the “node” link group; that is done for you when you install and remove the RPM through yum.
Beyond Node.jsAlthough update-alternatives is currently only used as a replacement for our home-brewed nodever, that was just one of the reasons that the utility was brought to IBM i. In the future, additional open-source packages will likely be converted to take advantage of the update-alternatives system. This might include gcc, the compiler system that builds all of the open-source software on the system and is comprised of many versioned files across the system. Or, of more interest to users, it might include languages like Python or PHP, where there is a need for switching an entire system from one version to another easily while keeping multiple versions installed on the system. We aren’t ready to announce anything yet, but rest assured that any skills you gain using update-alternatives with Node.js will transfer to other packages as well.
I hope that this blog waylaid any fears about upgrading from nodever to update-alternatives, and given you all the knowledge you need to make the transition with confidence. If you have any questions about how to use update-alternatives or any other open-source package delivered on IBM i, feel free to reach out to me on Twitter @markdirish or at firstname.lastname@example.org.
Mark Irish is a staff software developer at IBM, specializing in open source on IBM i.