How to create symbolic link in Mabox Linux (Manjaro) [with screenshots]

Written by Administrator on Thursday April 9, 2020

Sometimes happens, that you've installed software into .. some 'strange' directory, for example into you /home folder or /home/$USER/Download folder. And it means that you have to go into that folder and run a command. It's not comfortable. Linux has solution! You can use command-line utility ls to create a link between two files.

Rule is very simple:

$ ls -s <path_to_source_file> <path_to_link>

Let's look on real example in my system:

I have downloaded npm packet manager (node-v12.16.2-linux-x64.tar.xz  file ) in my /home/dima/Downloads folder and unpack it right there, in /home/dima/Downloads/node-v12.16.2-linux-x64 folder. Yes, installing new program in home directory is against Linux Filesystem Hierarchy Standard, but .. shit happens.

So, now, in order to launch nodejs, which I've downloaded, I have to go to:

/home/dima/Downloads/node-v12.16.2-linux-x64/bin

and run command:

[dima@dima-edustorage-net bin]$ ./node
Welcome to Node.js v12.16.2.
Type ".help" for more information.
> 

It's not very comfortable, because I don't want to enter this directory every time I want to launch node environment. I want to launch it regardless the directory I'm currently in. Linux has its solution for those cases. We can create symbolic link (symlink), which is a special type of file that points to another file of directory. A kind of shortcut.

So, our executable file's location is /home/dima/Downloads/node-v12.16.2-linux-x64/bin,

It means, that when I am in /home/dima/ directory and want to launch this file:

$ cd /home/dima/
$ node --version

bash will tell me, that it doesn't know this command:

[dima@dima-edustorage-net ~]$ node --version
bash: node: command not found

In order to have an abilitity to launch it from every folder in our system, we can create symlink:

$ sudo ln -s /home/dima/Downloads/node-v12.16.2-linux-x64/bin /usr/bin/node

Symlink is created!

Now we can check, how it works now:

$ node --version

and our output:

[dima@dima-edustorage-net ~]$ pwd
/home/dima
[dima@dima-edustorage-net ~]$ node --version
v12.16.2
[dima@dima-edustorage-net ~]$ 

It works exactly the way we wanted!

Category: linux Tags: ln mabox-linux symlinks node_js