In today’s rapidly evolving world of web development, having a robust and efficient development environment is crucial. In this blog post, we will walk you through the process of setting up Node.js and Yarn on Debian-based Distributions, empowering you to create and manage your JavaScript projects with ease. Node.js, a powerful runtime environment, coupled with Yarn, a dependable package manager, will streamline your workflow and enhance your productivity. So, let’s dive into the step-by-step guide and get started on the path to efficient development!
Step 1: Removing Node.js
To ensure a clean slate for our installation, let’s first remove any existing Node.js installations. Open up your terminal and execute the following command:
sudo apt remove nodejs
Step 2: Installing NVM (Node Version Manager)
NVM is a versatile tool that facilitates the management of different Node.js versions. Let’s proceed with its installation by entering the following command:
curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.0/install.sh | bash
Step 3: Checking NVM Version
Verifying the successful installation of NVM is vital. Run the following command to ensure that NVM has been set up properly:
nvm --version
Step 4: Configuring Bash
To make NVM readily available every time you open a terminal, we need to configure the Bash shell. Let’s do that by adding the necessary line to the .bashrc
file using the Nano text editor:
nano ~/.bashrc
Once the file is open, add the following line at the end:
source ~/.nvm/nvm.sh
Save the changes and exit Nano by pressing Ctrl + X
, then Y
, and finally Enter.
Step 5: Activating NVM
To activate NVM and set a specific version of Node.js as active, execute the following command:
source ~/.nvm/nvm.sh
Step 6: Installing Node.js
Now it’s time to install Node.js itself. As an example, we’ll install version 18.16.0
, but feel free to use any version you prefer:
nvm install 18.16.0
Step 7: Setting the Default Node.js Version
Setting a default Node.js version can be handy. To do so, enter:
nvm alias default 18.16.0
Step 8: Checking Node.js and npm Versions
To double-check that Node.js has been installed correctly, verify its version:
node -v
Similarly, confirm the installed version of npm with:
npm -v
Step 9: Installing Yarn
Yarn, a swift and dependable package manager, can greatly enhance your development experience. Install it globally with the following command:
npm install -g yarn
Step 10: Verifying Yarn Installation
Ensure that Yarn has been installed successfully by checking its version:
yarn -v
Congratulations!
You’ve successfully set up Node.js and Yarn on your linux environment. With these powerful tools at your disposal, you’re now equipped to embark on your development journey. Whether you’re building intricate web applications or crafting elegant scripts, Node.js and Yarn will be your steadfast companions. Remember, if you encounter any hurdles or have questions along the way, the Node.js and Yarn communities are here to assist.