Create a link in Unix

A symbolic link is a special form of a file. Actually it is not a file just a pointer to a file. This link points to another file somewhere in the file system. You can create link to files and folders. By the look, feel and functionality it is same as Windows shortcut or alias on iOS systems. If the content of the original file changes, so does the content of symlink. If the original file is moved, renamed or deleted, then the symbolic link stops working correctly (called hanging link). Removing the link doesn't affect the original file in any way. You can symlink files accros network too. The symbolic link is often called a soft link or shortly symlink.

To create a symbolic link, type this command:


    ln -s OriginalFilename TargetLinkedFilename

It is good practice to use full system path altogether with filename.

There are also Hard links, which reference rather to the source of file. While Symbolic link references to the pathname of the target. So the Hard links have actual file contents. The original filename is actually a hard link too. So when you create a new hard link you are pointing to the same physical file in the system. The new hard link is added to list of links for the file. The Hard links can link only to files. We cannot create hard links for folders to avoid recursive loops. If the original link is removed the new hard link will still show the content of the file. Effectively removing any link, just reduces the link count, but doesnt affect other links.

To create hard link, type this command:


    ln OriginalFilename TargetFilename

That's all, now enjoy linking.

Tags: unix, ubuntu, symlink


Install NVM (Node Version Manager) for Node.js on Ubuntu 18.04

Node.js

Node.js is javascript runtime. I am not going to explain why and how it can be used, you can check yourself on https://nodejs.org/en/about/. But the fact is that Node.js comes in different versions and if you used it in past, you might be familiar that sometimes you just need other version, sometimes newer version, other times older version. There is a easy way to manage those versions with a single command and that's what I want to introduce you to today. the tool is called NVM, which is shortcut to Node Version Manager. I will show you how to install the latest version on Ubuntu 18.04 although the same steps shwould work on any unix like system.

Installing latest NVM

First we need to check what is the latest version of NVM from github. We can go directly to https://github.com/creationix/nvm/releases and make note of latest release. At the time of writing it was v0.34.0, so that is version of NVM we are going to install.

First we will update packages and install build-essential, which should be already installed, but in case it isn't


    apt update
    apt install build-essential libssl-dev

Next we will download the nvm using curl and execute the install script:


    curl https://raw.githubusercontent.com/creationix/nvm/v0.34.0/install.sh | bash

After this step we need a fresh terminal, so please close and reopen terminal to start using nvm. We can now validate that the nvm is installed correctly with command


    nvm --version

which in my case outputs 0.34.0. Great. Now we can start to use it. I suggest, let's check all LTS (long term support) versions of nodejs and install the latest one


    nvm ls-remote --lts
    nvm install 10.15.1

And that's it. As you can see we just installed latest version of Node.js and npm into our system. You can easily validate with commnads


    stefan@ubuntu:~/$ npm -v
    6.4.1
    stefan@ubuntu:~/$ node -v
    v10.15.1

Once you install more versions you don't have to uninstall them, just switch the version using nvm use 10.15.1 which will change version until you close terminal. If you want permanently switch to other version of nvm then just run nvm alias default 10.15.1 Thank you attention. That's all for today.

Tags: nvm, npm, nodejs