Npm command not recognized (ubuntu) - ubuntu-16.04

After installing java 8 openjdk and exporting the variable via export I ran the following command:
source /etc/enviorment
I after that when I try to run npm run tests-e2e, it says the command is not recognized.

Executing source /etc/environment has reset your shell's environment variables back to their default values, throwing away any customisations that were applied by your shell's startup scripts (/etc/profile, ~/.bash_profile and so on). In particular, it looks like you've lost the customised value of $PATH that carried the path to the directory where the npm command lives.
To recover, you can do any of:
execute exec bash -l to get a new shell that will execute the
startup scripts and therefore rebuild a properly customised $PATH variable
if you're using the GUI, close the terminal window and open a new one
log out and then log back in

Related

Swift on Ubuntu 20.04- Need to add a path every time

I am simply trying to install swift on linux
I have downloaded the files from swift.org, extracted .tar files and used export command to include the path after that when I use swift --version it correctly shows the version 5.3.3 but when I close the terminal and try to open the swift command terminal it says command not found.
What is happening here? I need to include the path every time I open the terminal.
The export command just adds the value to path for the current session. When you log out and in again, it will reset.
You need to add this to your shell resource file so that it gets added to the path every time you log in. The file you need to edit will be called .zshrc or .bash_profile or something similar. You should start by opening the command line on your computer and verifying what shell you are running by typing:
echo $SHELL
This will return something like /bin/ksh or /bin/bash or similar. Then do a little internet searching to find out what the resource file is called for that shell. Then edit your resource file to add the Swift path to your $PATH.

Run a virtual environment globally?

Is there any way to make workon global? For example; I open terminal and type workon myenvname --global, then I open another terminal window and type something like python myscript.py and it will run it under the myenvname environment?
Also I can then open Sublime Text IDE and create a python script, then press CTRL+b and the python script will run in the myenvname environment.
Is such a thing possible?
No. Virtual environments must be activated in every shell (i.e., every terminal) separately.
There is no magic in Python virtual environments. Their activation just sets a few environment variables; the most important is PATH so that the current shell finds python and pip. Then python being run from a virtual env detects it and sets sys.path accordingly.
To some extent you can do a trick without activation: run python from a virtual env:
/path/to/venv/bin/python myscript.py
Hope it helps someone
You may not be able to run it globally but if you want to run a particular python script without entering into the virtualenv. Here's a work around.
Considering you are using this on linux.
Say you have a virtualenv called myenvname
You would like to run a particular python script myscript.py inside this particular myenvname without even using terminal by just double click on an icon.
Create a shell script myshellscript.sh
#!/bin/bash
# open the virtual environment
source /home/usr_name/.virtualenvs/myenvname
# location to the python script you want to run
# python/python3 depending on the version you are using
python location/to/your/python/script/myscript.py
Give permission for myshellscript.sh to be an executable
chmod +x myshellscript.sh
Create a .desktop file inside /usr/share/applications/
sudo nano /usr/share/applications/myscript.desktop
copy paste the block of code and make the changes accordingly
[Desktop Entry]
Version=1.0
Type=Application
Terminal=false
Exec=shellscript file to be run along with its path
Path=directory where the file is located
Name=myscript
Comment=comment here
Icon=icon path here
then give permission to the myscript.desktop
chmod +x /usr/share/applications/myscript.desktop
You are done.
Just goto /usr/share/applications/ and double click on myscript icon, you got your myscript.py running

nvm, node etc. paths missing from integrated terminal

I am using the insiders edition and zsh with ohmyzsh inside iTerm2 on OSX High Sierra.
If I launch the integrated command line in VSCode echo $path returns:
/Users/username/.yarn/bin:/Users/username/.cargo/bin:/usr/bin:/usr/bin/lldb:
/Users/username/bin:/usr/local/bin:/Users/username/.scripts:
/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/opt/X11/bin
Obviously, the node path, nvm path etc. are missing so the terminal is not much use to me.
But typing echo $path in my terminal outside of VSCode returns:
/Users/username/.nvm/versions/node/v9.0.0/bin /Users/username/.yarn/bin
/Users/username/.cargo/bin /usr/bin /usr/bin/lldb /Users/username/bin
/usr/local/bin /Users/username/.scripts /usr/local/bin /usr/bin /bin /usr/sbin
/sbin /opt/X11/bin
Which has all the paths I need for my development activities.
I have this alias in my ~/.zshrc:
code () { VSCODE_CWD="$PWD" open -n -b "com.microsoft.VSCodeInsiders" --args $* ;}
If I launch code using the alias from an external terminal the node paths are correct.
As far as I can see this is because loading code from the Dock shortcut doesn't load the terminal using my user profile so it loads the profile from /etc/zprofile instead, which sets the path using /usr/libexec/path_helper so it misses all of my important paths that I need for development.
I suspect that most people would prefer the settings from their user profiles to be used. This would mean all of our dev apps would work from the integrated terminal and also the end of the infamous nvm is not compatible with the npm config "prefix" option error caused by the improper setting of paths.
How can I get VSCode to use the environment of the terminal in my user profile when launched from the Dock?
Go to settings and edit integrated terminal
// Object with environment variables that will be added to the VS Code process to be used by the terminal on OS X
"terminal.integrated.env.osx": {},
there you can pass in your variables
The vscode docs also offer a solution for the warning nvm is not compatible with the npm config "prefix" option: currently set to "/usr/local":
https://github.com/Microsoft/vscode-docs/blob/master/docs/editor/integrated-terminal.md#why-is-nvm-complaining-about-a-prefix-option-when-the-integrated-terminal-is-launched
From the docs:
This is mostly a macOS problem and does not happen in external
terminals. The typical reasons for this are the following:
npm was globally installed using another instance of node which is
somewhere in your path (such as /usr/local/bin/npm). In order to get
the development tools on the $PATH, VS Code will launch a bash login
shell on start up. This means that your ~/.bash_profile has already
run and when an Integrated Terminal launches, it will run another
login shell, reordering the $PATH potentially in unexpected ways. To
resolve this issue, you need to track down where the old npm is
installed and remove both it and its out of date node_modules. You can
do this by finding the nvm initialization script and running which npm
before it runs, which should print the path when you launch a new
terminal.
Once you have the path to npm, you can find the old node_modules by
resolving the symlink by running a command something like this:
ls -la /usr/local/bin | grep npm
This will give you the resolved path at the end:
... npm -> ../lib/node_modules/npm/bin/npm-cli.js
From there, removing the files and relaunching VS Code should fix the issue:
rm -R /usr/local/bin/npm /usr/local/lib/node_modules/npm/bin/npm-cli.js

ionic install fails on fsevents on Windows

I have tried to install ionic on Windows but installation has failed. What should I do?
I have tried more than 20 times but still I got the same problem.
Here I have attached the screenshot for this
Entered commands:
npm install -g cordova
npm install -g ionic
Note: this one windows server machine
My guess is that the NPM global path has not been added to your windows path.
These are the steps to try:
First verify that the command just installed can run. The output contains the full path to the command installed, just copy and paste it to the command line. In your case it might be something like this %APPDATA%\Roaming\npm\iconic -v
Lets assume that works. That means that the command was successfully installed and will run, now we need to add it to your PATH so you can run it from the command line.
Next, Press Windows key and type "path" and select "Edit environment variables for your account". From here. Add or append the path %APPDATA%\Roaming\npm to your PATH variable, and save the results.
Once it is on your PATH you can run it from any command shell window.
Next, start a new command shell (e.g., Windows+R, cmd, Enter) and then type the command iconic -v. Viola, it should work without requiring the full path to the script.
I'm doing most of this from memory so hopefully it's correct. But if it needs some tweeks, let me know and I'll update the answer.
For completness, this install didn't actually fail. The lines with fsevents are warnings. The fsevents package is only designed to work on Mac Unix so these warnings can be safely ignored.
As Suraj Rao mentioned, also see Nodejs cannot find installed module on Windows?.

Configure Eclipse to use bash login shell for Cygwin toolchain

I have a custom Makefile project in Eclipse and although the build does get run in a Cygwin shell... it does not seem to be a login shell (bash --login) as it doesn't set my environment variables like running cygwin.bat does.
Where in Eclipse can I change the shell command so that it will be a login shell?
What you actually aim with bash --login are your settings from /etc/profile.
Under UNIX you normally have only one login shell and so these settings are inherited by all other shells. Under Windows any Bash window is an isoloated login shell, which leads to missing environment settings when running Bash from tools that run bash simply as command processor.
I had a similar problem with Emacs compile feature. The best solution under Windows is to set the environment variable BASH_ENV to a script. Bash will execute this script when started without -i or --login, so that /etc/profile is not run. Hence the script will setup Bash for non-interactive, non-login shells.
Example:
BASH_ENV=%USERPROFILE%\.bash_env
as user environment variable. The least thing to do in this script is to set PATH as in /etc/profile:
PATH="/usr/local/bin:/usr/bin:${PATH}"
Check the path-settings in /etc/profile as it is created by Cygwin's setup.exe. You may also copy settings from ~/.bashrc or source this script.
Hope this helps.