node: command not found - in wsl bash [duplicate] - linux

This question already has answers here:
How can I run a Windows executable from WSL (Ubuntu) Bash
(6 answers)
Closed 5 months ago.
I install docker on my windows 10. after that I get a message that I need to download and install wsl2.
Now, when I run bash command I get wsl bash.
When I try to run node I get an error (node.exe is installed in my windows10):
DESKTOP-BVRDS:/tmp/docker-desktop-root/mnt/host/c/Users/myuser# node
bash: node: command not found
when I run echo $PATH I get output of:
/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
and not the windows path's. (where the node and other software installed).
How to solve this error? maybe change the default bash? to git bash? (which I don't know how)

In Cmder, open settings: Win + Alt + P
Under Startup > Tasks, add a task called {bash} with the following settings:
Task parameters (set icon):
For Cmder icon: /icon "%CMDER_ROOT%\cmder.exe"
For Git icon: /icon "C:\Program Files (x86)\Git\etc\git.ico"
Commands (open Git's bash shell):
"C:\Program Files (x86)\Git\bin\sh.exe" -l -new_console:d:%USERPROFILE%
Under Startup, set startup options to Specified name task --> {bash}
Please check below a couple of articles and should solve an issue.
https://gist.github.com/nickautomatic/02ccb76292f7f8d9767e
https://gingter.org/2016/11/16/running-windows-10-ubuntu-bash-in-cmder/

Please try below:
Open a regular command prompt (win+r then cmd)
Right-click the title bar and select Properties
Deselect "Use legacy console (requires restart)"
Now it should work either by launching the standalone app, or typing bash into a regular cmd window after restarting Command Prompt.

Related

How can I run Gitk on WSL 2?

How can I run Gitk on WSL 2?
I already installed Gitk in WSL 2.
After I installed Gitk, I tried to run it but it failed with below error log:
application-specific initialization failed: no display name and no $DISPLAY environment variable
Error in startup script: no display name and no $DISPLAY environment variable
while executing
"load /usr/lib/x86_64-linux-gnu/libtk8.6.so Tk"
("package ifneeded Tk 8.6.8" script)
invoked from within
"package require Tk"
(file "/usr/bin/gitk" line 10)
Could you help me how can run Gitk on WSL 2?
You can install and run gitk straight from ubuntu terminal on Windows 11, using apt install.
I've just followed the steps from the following post and it worked:
https://learn.microsoft.com/en-us/windows/wsl/tutorials/gui-apps
I had to update not only the graphic driver but also the WSL.
Now, I can use either gitk or any linux app on Windows 11.
If git is installed on windows, you can find the gitk.exe by typing the following command to windows cmd:
where gitk
you can reach this folder from your wsl by changing the path e.g. from
C:\Git\cmd\gitk.exe
to
/mnt/c/Git/cmd/gitk.exe
and by typing this path to the terminal of your linux distribution, gitk can be opened.
UPDATE:
If you want to open gitk by typing it, you can add the path to ~/.bashrc with the following command (needed only once):
echo 'alias gitk="/mnt/c/Git/cmd/gitk.exe"' >> ~/.bashrc
And after that you can open gitk like:
gitk

pipenv shell working but an error is displayed

If I run the command:
pipenv shell
in my Mac shell, everything works fine and a new virtual environment is created and activated:
.../django_celery_rabbit_flower$ pipenv shell
Launching subshell in virtual environment...
bash: parse_git_branch: command not found
.../django_celery_rabbit_flower$ . /.../django_celery_rabbit_flower-rEt8HW1V/bin/activate
bash: parse_git_branch: command not found
(django_celery_rabbit_flower) .../django_celery_rabbit_flower$
but a bash error is displayed:
bash: parse_git_branch: command not found
I do not understand where it come from. Any idea?
UPDATE
Jen answer trigger a little thought. I have checked my ./bash_profile and I can see the line:
export PS1="\[\033[36m\]\u\[\033[m\]#\[\033[32m\]\h:\[\033[33;1m\]\w\[\033[m\]\$(parse_git_branch)\$ "
This shows the git branch on the bash prompt. So I believe vscode uses this settings. The folder I am working on is not a git folder. Can I write an if statement to avoid the error being displayed when running the python virtual environment?
Instead make sure that the command does actually exists before running it.
PS1="...."'$(if hash parse_git_branch >/dev/null 2>&1; then parse_git_branch; fi)'"..."

How to change WebStorm enviroment settings for File Watcher?

I have simple File Watcher that run TSLint. If I copy the command and run it in the console all fine but WebStorm run it with old Node version and throw error Buffer.alloc is not a function.
I'm using nvm to manage node.js versions.
ubuntu 16.4
Different Node.js versions are on your $PATH when you start your script from the IDE and from terminal.
When being launched from desktop/System menu, WebStorm only sees environment variables configured in login shell, but not in interactive shell configuration files (like .bashrc or .zshrc).
Possible workarounds:
Workaround 1: make required variables available in a login shell by moving them to the corresponding shell profile config
Workaround 2: run IDE from a terminal, either with the command line launcher or with bin/webstorm.sh
Workaround 3: edit the desktop launcher and set command to /path/to/shell -l -i -c "/path/to/webstorm.sh" (make sure that the shell you specified there has the needed variables configured in its interactive shell configuration file)
see also https://youtrack.jetbrains.com/issue/IDEABKL-7589

Git bash or NPM on Windows is converting an argument into a path [duplicate]

This question already has answers here:
How to prevent MSYS to convert the file path for an external program
(3 answers)
Closed 3 years ago.
I am writing a node.js script to patch server files. Our development machines are Windows, but the servers are Linux.
When I execute run the following script:
npm run patch-file --source-file "/path/to/file" --destination "/path/to/file"
Somewhere between Git bash or NPM the arguments are converted to windows paths. Which I don't want to happen here. I am handling the path conversion based on the source/ destinaiton in the script itself.
Actual Output:
node ./scripts/patch-file.js "--source-file" "C:/Git/path/to/file" "--destination" "C:/Git/path/to/file"
Expected output:
node ./scripts/patch-file.js "--source-file" "/path/to/file" "--destination" "/path/to/file"
Notes
This seems to be isolated to Git bash, I can't replicate it using windows command prompt or powershell. I'd still like to figure this out, because I would like this to work seemlessly between command terminals.
I believe that you are looking for the environment variable MSYS_NO_PATHCONV=1, as discussed here or here.
I did a test with notepad.exe. While this worked and opened the text file from the root of the Git for Windows installation
notepad.exe /LICENSE.txt
suggesting that the path conversion took place, this failed with notepad.exe complaining that the file /LICENSE.txt couldn't be found
MSYS_NO_PATHCONV=1 notepad.exe /LICENSE.txt
So, I think that the latter form is what you need.
Note that MSYS_NO_PATHCONV seems to be really specific to Git for Windows and is not available in other MSYS2-based terminals.

"Shell Command: Install" command missing from Command Palette - VS code - ubuntu

I cannot find the command to install shell commands to the path on the Command Palette in VS code for Ubuntu.Is it possible that something went wrong during the installation, or is there a solution that I am missing?
When I type in "Shell", my options are "Terminal: Allow Workspace Shell Configuration" and "Python: Run Selection/Line in Django Shell". There is nothing listed to Install a Shell command.
With latest version of vscode you should be able to ctrl + shift + p or cmd + shift + p (or whatever the hotkey is on ubuntu) and search for shell and then get what you see in the image.
It is said on the Vscode documentation: "Note: Users on macOS must first run a command (Shell Command: Install 'code' command in PATH)", so maybe the command is only available when running vscode from mac, and not ubuntu (and windows for that matter)? I don't know

Resources