Challenges with utilizing Node.js on zsh

Recently, I made the switch from the bash shell to zsh while running Ubuntu via WSL. Initially, Node.js was installed and up to date on bash. However, when I tried npm install on a project in zsh, I realized that Node wasn't installed for zsh. Despite my efforts to install Node on zsh, I encountered issues as it never seemed to install the latest version. Every time I attempted to run npm, I received an error message stating zsh: command not found: npm.

I have attempted to uninstall Node from zsh and reinstall it in hopes of resolving the issue. However, each time I reinstall, it defaults to an older version of Node without npm. Even after using commands like sudo apt install nodejs and sudo apt install npm, the problem persists.

Answer №1

Typically, the default shell used is bash.

To import all available commands from bash, follow these steps:

Open your ~/.zshrc file with any text editor, and insert the following line at the beginning of the file:

source /home/YOUR_USERNAME/.bash_profile

If you only need to add node, append the following line to your bash configuration:

'export NODE_PATH=~/local/:~/local/node_modules' >> ~/.zshrc

Answer №2

Discovered the root of the problem. It appears that when Oh My ZSH was installed, the path to the node and nvm files installed from bash was not properly linked. To resolve this issue, I needed to insert

export PATH=/home/MYUSERNAME/.nvm/versions/node/v18.14.1/bin:$PATH
at the beginning of the zshrc file, right below the initial commented line that mentions adjusting $PATH if switching from bash. Additionally, I made sure to comment out the old PATH in case it might be needed in the future.

You can edit the zshrc file by using nano ~/.zshrc.

To identify your current zsh file path, use echo $PATH. If you need to switch back to bash to check your path, use chsh -s /bin/bash. Get the node path from your bash environment by running echo $PATH and copying the relevant section into your zshrc file.

To go back to zsh shell, run chsh -s /bin/zsh.

You can confirm which terminal you are using with echo $0.

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Dividing socket.io namespaces into distinct files

Having developed two socket.io applications, one for an interactive game and the other for a chat feature, I decided to segregate them by creating separate namespaces. Now, my objective is to extract these apps from the main file app.js and store them in ...

Tips for efficiently adding a like feature to a MEAN web application

Currently, I am in the process of developing a web application that allows users to express their preferences by liking certain choices displayed on the page. I am trying to optimize the efficiency of the like/unlike system. My main question is whether ev ...

Guide to setting up npm pug-php-filter in conjunction with gulp

I'm having trouble setting up pug-php-filter (https://www.npmjs.com/package/pug-php-filter) with gulp in order to enable PHP usage in my Pug files. Any assistance would be greatly appreciated. ...

What strategies are most effective for handling sessions in Node.js?

Currently, I am delving into the world of Node.js and I find myself pondering the best approach to handle sessions. Upon my investigation, it appears that there are primarily two options available: express-session and cookie-session. Sources suggest that ...

Error message: Uncaught TypeError - Unable to access undefined properties (specifically 'call') during build mode, not in development mode

My Vite.js application with web3 running smoothly in development mode encounters an issue when switched to production mode. The error message that pops up reads: "TypeError: Cannot read properties of undefined (reading 'call')". The root cause o ...

Kindly include a @Pipe/@Directive/@Component annotation within an Angular 6 project

Encountering an issue in Angular6 where I am receiving the error message Please add a @Pipe/@Directive/@Component annotation Using angular CLI version: 6.1.4 angular version: 6.1.3 Node: 10.9.0 NPM: 6.2.0 After running ng serve in Terminal, the applicati ...

What are the steps to authenticate on Azure Active Directory through LDAP using node.js?

This is all new to me. My users are on AAD and I want to authenticate them using node js. Can anyone provide some guidance on where to begin and the steps to take? ...

Unable to open browser using BrowserSync or live-server

Lately, I've been using live-server with VS Code to debug my web pages. Everything was working perfectly fine until one day, it suddenly stopped functioning. It seemed strange to me so I reinstalled Nodejs, but that didn't solve the problem. The ...

How to configure setup for running ES6 tests with Mocha 6 and Babel 7?

Looking to compile a library written in ES6/7 to ES5 and store it in a dist/ folder. Additionally, I need to run tests for this library. The development dependencies listed in my package.json file are as follows: "devDependencies": { "@babel/cli": "^7. ...

Jenkins Node Version Switch: No executables were located in the directory "/usr/local/n/versions/node/11.15.0/bin"

Every time I run my Jenkins pipeline, I keep encountering the following error: Couldn’t find any executable in "/usr/local/n/versions/node/11.15.0/bin" The Jenkins Slave is set up on an AWS Linux machine with both node 16.x and node 11.15.0 in ...

While loop not yielding immediate result with asynchronous function

As a beginner in Node.js, I have successfully connected an LCD Panel and a 4x4 Membrane matrix keypad to my Raspberry Pi. Using Node.js, I have programmed them to work together. My goal is to have the LCD panel immediately display any key pressed on the ke ...

Guide to setting up fabric.js with node.js

I am currently in the process of setting up fabric.js on my Synology NAS that already has node.js installed. Initially, I attempted to install it using bower by running the command `bower install fabric`. Although this downloaded and copied the necessary ...

Is it possible to extract the body from the post request using req.body.item?

After working with Express, I learned how to extract body data from a post request. Most examples showed that using req.body.item should retrieve the desired value for tasks like inserting into a table. However, in my case, I found that I couldn't ac ...

Guide to Making a Cookie Using Node's cookie-session Package

I'm currently working on a small node application and my goal is to have it create a cookie for every visitor, named 'session', which will store the session ID. However, I've been facing some challenges in getting node to generate this ...

Is it necessary to establish a fresh connection for every new API request?

I am currently developing my API server using Express JS, and I am connecting to my SQL Server DB with tedious. For each request logic, I am creating a new tedious Connection object, establishing a connection to the DB, executing the query, and then closi ...

I created a custom discord.js-commando command to announce all the channels that my bot is currently active in, however, encountered an unexpected error

const Commando = require('discord.js-commando'); module.exports = class AnnounceCommand extends Commando.Command { constructor(client) { super(client, { name: 'announce', aliases: ['an'], ...

How can one determine the source of an Express server-to-server request?

Is it possible to retrieve the source information of a remote server that is sending requests to my api server? I am looking for a way to prevent any potential spoofing of server-to-server authentication tokens. In my testing, I sent remote requests to th ...

What is the process for running "node server.js" within codelab?

I am currently going through a codelab tutorial on Bitbucket at this link After installing node.js for the first time, I encountered an error when trying to run the server.js file: node server.js The error message "node: Command not found" appeared even ...

What are the best practices for implementing serialization in NestJS?

Recently, I delved into a fresh NestJs project and encountered a hurdle while trying to integrate serialization. The goal was to transform objects before sending them in a network response. Initially, everything seemed to be working smoothly until I attemp ...

Is it possible to restrict access to partial views in node.js/express?

Is there a way to restrict access to certain partial views using node.js/express? In my single page web app, I have different views and I want to prohibit some pages from displaying unless the user is logged in. How can I achieve this? I understand that it ...