How to install pnpx - pnpm

I installed pnpm on linux with
curl -fsSL https://get.pnpm.io/install.sh | sh -
as explained at https://pnpm.io/installation . With this I got just pnpm but no pnpx installed. How can I install pnpx?
Since pnpx is deprecated, can it be that it does not exist anymore?
see https://pnpm.io/pnpx-cli

We're planning to deprecate pnpx. Use pnpm dlx and pnpm exec instead of pnpx. You may create an alias in your shell if you still want to call pnpx instead of pnpm dlx:
alias pnpx='pnpm dlx'
Also, for now pnpx is installed using the installation methods described here
On Linux or macOS:
curl -f https://get.pnpm.io/v6.16.js | node - add --global pnpm
On Windows (PowerShell):
Invoke-WebRequest 'https://get.pnpm.io/v6.16.js' -UseBasicParsing -o pnpm.js; node pnpm.js add --global pnpm; Remove-Item pnpm.js
Or using npm npm i -g pnpm.

Related

Cannot build dockerfile with sdkman

I am entirely new to the concept of dockers. I am creating the following Dockerfile as an exercise.
FROM ubuntu:latest
MAINTAINER kesarling
RUN apt update && apt upgrade -y
RUN apt install nginx curl zip unzip -y
RUN apt install openjdk-14-jdk python3 python3-doc clang golang-go gcc g++ -y
RUN curl -s "https://get.sdkman.io" | bash
RUN bash /root/.sdkman/bin/sdkman-init.sh
RUN sdk version
RUN yes | bash -c 'sdk install kotlin'
CMD [ "echo","The development environment has now been fully setup with C, C++, JAVA, Python3, Go and Kotlin" ]
I am using SDKMAN! to install Kotlin. The problem initially was that instead of using RUN bash /root/.sdkman/bin/sdkman-init.sh, I was using RUN source /root/.sdkman/bin/sdkman-init.sh. However, it gave the error saying source not found. So, I tried using RUN . /root/.sdkman/bin/sdkman-init.sh, and it did not work. However, RUN bash /root/.sdkman/bin/sdkman-init.sh seems to work, as in does not give any error and tries to run the next command. However, the docker then gives error saying sdk: not found
Where am I going wrong?
It should be noted that these steps worked like charm for my host distribution (The one on which I'm running docker) which is Pop!_OS 20.04
Actually the script /root/.sdkman/bin/sdkman-init.sh sources the sdk
source is a built-in to bash rather than a binary somewhere on the filesystem.
source command executes the file in the current shell.
Each RUN instruction will execute any commands in a new layer on top of the current image and commit the results.
The resulting committed image will be used for the next step in the Dockerfile.
Try this:
FROM ubuntu:latest
MAINTAINER kesarling
RUN apt update && apt upgrade -y
RUN apt install nginx curl zip unzip -y
RUN apt install openjdk-14-jdk python3 python3-doc clang golang-go gcc g++ -y
RUN curl -s "https://get.sdkman.io" | bash
RUN /bin/bash -c "source /root/.sdkman/bin/sdkman-init.sh; sdk version; sdk install kotlin"
CMD [ "echo","The development environment has now been fully setup with C, C++, JAVA, Python3, Go and Kotlin" ]
SDKMAN in Ubuntu Dockerfile
tl;dr
the sdk command is not a binary but a bash script loaded into memory
Shell sessions are a "process", which means environment variables and declared shell function only exist for the duration that shell session exists; which lasts only as long as the RUN command.
Manually tweak your PATH
RUN apt-get update && apt-get install curl bash unzip zip -y
RUN curl -s "https://get.sdkman.io" | bash
RUN source "$HOME/.sdkman/bin/sdkman-init.sh" \
&& sdk install java 8.0.275-amzn \
&& sdk install sbt 1.4.2 \
&& sdk install scala 2.12.12
ENV PATH=/root/.sdkman/candidates/java/current/bin:$PATH
ENV PATH=/root/.sdkman/candidates/scala/current/bin:$PATH
ENV PATH=/root/.sdkman/candidates/sbt/current/bin:$PATH
Full Version
Oh wow this was a journey to figure out. Below each line is commented as to why certain commands are run.
I learnt a lot about how unix works and how sdkman works and how docker works and why the intersection of the three give very unusual behaviour.
# I am using a multi-stage build so I am just copying the built artifacts
# from this stage to keep final image small.
FROM ubuntu:latest as ScalaBuild
# Switch from `sh -c` to `bash -c` as the shell behind a `RUN` command.
SHELL ["/bin/bash", "-c"]
# Usual updates
RUN apt-get update && apt-get upgrade -y
# Dependencies for sdkman installation
RUN apt-get install curl bash unzip zip -y
#Install sdkman
RUN curl -s "https://get.sdkman.io" | bash
# FUN FACTS:
# 1) the `sdk` command is not a binary but a bash script loaded into memory
# 2) Shell sessions are a "process", which means environment variables
# and declared shell function only exist for
# the duration that shell session exists
RUN source "$HOME/.sdkman/bin/sdkman-init.sh" \
&& sdk install java 8.0.275-amzn \
&& sdk install sbt 1.4.2 \
&& sdk install scala 2.12.12
# Once the real binaries exist these are
# the symlinked paths that need to exist on PATH
ENV PATH=/root/.sdkman/candidates/java/current/bin:$PATH
ENV PATH=/root/.sdkman/candidates/scala/current/bin:$PATH
ENV PATH=/root/.sdkman/candidates/sbt/current/bin:$PATH
# This is specific to running a minimal empty Scala project and packaging it
RUN touch build.sbt
RUN sbt compile
RUN sbt package
FROM alpine AS production
# setup production environment image here
COPY --from=ScalaBuild /root/target/scala-2.12/ $INSTALL_PATH
ENTRYPOINT ["java", "-cp", "$INSTALL_PATH", "your.main.classfile"]
Generally you want to avoid using "version manager" type tools in Docker; it's better to install a specific version of the compiler or runtime you need.
In the case of Kotlin, it's a JVM application distributed as a zip file so it should be fairly easy to install:
FROM openjdk:15-slim
ARG KOTLIN_VERSION=1.3.72
# Get OS-level updates:
RUN apt-get update \
&& apt-get install --no-install-recommends --assume-yes \
curl \
unzip
# and if you need C/Python dependencies, those too
# Download and unpack Kotlin
RUN cd /opt \
&& curl -LO https://github.com/JetBrains/kotlin/releases/download/v${KOTLIN_VERSION}/kotlin-compiler-${KOTLIN_VERSION}.zip \
&& unzip kotlin-compiler-${KOTLIN_VERSION}.zip \
&& rm kotlin-compiler-${KOTLIN_VERSION}.zip
# Add its directory to $PATH
ENV PATH=/opt/kotlinc/bin:$PATH
The real problem with version managers is that they heavily depend on the tool setting environment variables. As #JeevanRao notes in their answer, each Dockerfile RUN command runs in a separate shell in a separate container, and any environment variable settings within that command get lost for the next command.
# Does absolutely nothing: environment variables do not stay set
RUN . /root/.sdkman/bin/sdkman-init.sh
Since an image generally contains only one application and its runtime, you don't need the ability to change which version of the runtime or compiler you're using. My Dockerfile example passes it as an ARG, so you can change it in the Dockerfile or pass a docker build --build-arg KOTLIN_VERSION=... option to use a different version.

go-swagger: command not found

Trying to install go-swagger on Ubuntu.
I have installed brew(Linuxbrew):
sh -c "$(curl -fsSL https://raw.githubusercontent.com/Linuxbrew/install/master/install.sh)"
Next I did:
brew tap go-swagger/go-swagger
brew install go-swagger
typing swagger version
it answers: swagger: command not found.
anything else(-help, -version not working too)
What I did wrong?
Use this:
git clone https://github.com/go-swagger/go-swagger
cd go-swagger
go install ./cmd/swagger
Verify using:
swagger version
Running brew tap go-swagger/go-swagger && brew install go-swagger and then re-running command go-swagger worked for me. Any more details that can be provided here?
This command may also assist you, since you're utilizing go already... might be problematic if utilizing go modules or not.
go get -u github.com/go-swagger/go-swagger/cmd/swagger
You're missing $GOPATH/bin in your path reason why it cannot find the it
Potential fix:
echo 'export PATH="${GOPATH-"~/go"}/bin:$PATH"' >> ~/.bashrc
source ~/.bashrc
To install go-swagger run below command in GO PATH
go get -u github.com/go-swagger/go-swagger/cmd/swagger
To check the version and help run
swagger version
swagger -h

how to install pnpm without first installing npm

I am sitting in front of a completely clean windows 10 install – VS Code is installed but nothing else:
Is it possible to install and use pnpm without installing npm?
Is doing that a good thing or bad thing? context - typescript
There's a standalone script on pnpm installation guide.
curl -L https://unpkg.com/#pnpm/self-installer | node
Windows doesn't have curl, instead you can use Invoke-WebRequest within PowerShell for that. So probably this should work:
Invoke-WebRequest -Uri https://unpkg.com/#pnpm/self-installer | node
Update
Try downloading file instead and then executing it with node:
Invoke-WebRequest -Uri https://unpkg.com/#pnpm/self-installer -OutFile pnpm.js; node pnpm.js
Your second question is unclear.
Another approach is using COREPACK
corepack enable pnpm

nvm with yarn Yarn requires Node.js 4.0 or higher to be installed

I have nvm:
nvm ls
v8.11.3
v8.11.4
-> v11.1.0
default -> 8.11.4 (-> v8.11.4)
node -> stable (-> v11.1.0) (default)
stable -> 11.1 (-> v11.1.0) (default)
I installed yarn with:
sudo apt-get install --no-install-recommends yarn
I also added in .bashrc alias node=nodejs. But when I try yarn install I see:
Yarn requires Node.js 4.0 or higher to be installed.
How can I fix it?
This gist helped on this problem.
Run the following commands
echo "==> Installing Yarn package manager"
rm -rf ~/.yarn
curl -o- -L https://yarnpkg.com/install.sh | bash
# Yarn configurations
export PATH="$HOME/.yarn/bin:$PATH"
yarn config set prefix ~/.yarn -g
And add the following in ~/.bashrc
export PATH="$HOME/.yarn/bin:$HOME/.config/yarn/global/node_modules/.bin:$PATH"
It should then work properly without the warning after restarting the shell.
First uninstall the nodejs package:
sudo apt remove nodejs
Ubuntu 16.04 contains a version of Node.js in its default repositories that can be used to easily provide a consistent experience across multiple systems. At the time of writing, the version in the repositories is v4.2.6. This will not be the latest version, but it should be quite stable and sufficient for quick experimentation with the language.
In order to get this version, we just have to use the apt package manager. We should refresh our local package index first, and then install from the repositories:
sudo apt-get update
sudo apt-get install nodejs
If the package in the repositories suits your needs, this is all you need to do to get set up with Node.js. In most cases, you’ll also want to also install npm, which is the Node.js package manager. You can do this by typing:
sudo apt-get install npm
This will allow you to easily install modules and packages to use with Node.js.
Because of a conflict with another package, the executable from the Ubuntu repositories is called nodejs instead of node. Keep this in mind as you are running software.
To check which version of Node.js you have installed after these initial steps, type:
nodejs -v
Screenshot for nodejs version
I just want to mention that my configuration file looked something like that
export PATH=$PATH:`yarn global bin`
#NVM INITIALIZATION STUFF
(yarn docs recommended $PATH)
the export was before my nvm initialization. Which meant node was not available during the runtime of that line. So I just switched my configuration file to be
#NVM INITIALIZATION STUFF
export PATH=$PATH:`yarn global bin`
I had the same issue. by putting nvm path above yarn path didn't solve the issue then I looked up for a solution in man page and solve the issue by setting default node version on a shell.
Current lts version is v14.17.6 so i install it use it and set default node version on a shell.
nvm install --lts
nvm use --lts
nvm alias default <version>
Additional you can set always default to the latest available node version on a shell by running below command.
nvm alias node <version>

How can I update npm on Windows?

This question's answers are a community effort. Edit existing answers to improve this post. It is not currently accepting new answers or interactions.
I tried this:
sudo npm cache clean -f
sudo npm install -g n
sudo n stable
...but it didn't work.
How do I do this on Windows?
Note: The question is specifically asking how to upgrade npm, not Node.js. If you want to update Node.js over a CLI on windows, I recommend running winget upgrade -q NodeJS or use chocolatey for that.
What method should I choose to update NPM?
Node.js v16 or higher?
npm install -g npm
Node.js v14 or below?
Consider updating to latest LTS release of Node.js
npm-windows-upgrade
Upgrade with npm-windows-upgrade
Run PowerShell as Administrator
Set-ExecutionPolicy Unrestricted -Scope CurrentUser -Force
npm install -g npm-windows-upgrade
npm-windows-upgrade
Note: if you run the Node.js installer, it will replace the Node.js version.
Upgrades npm in-place, where Node.js installed it.
Does not modify the default path.
Does not change the default global package location.
Allows easy upgrades and downgrades and to install a specific version.
A list of versions matched between NPM and Node.js (https://nodejs.org/en/download/releases/) - but you will need to download the Node.js installer and run that to update Node.js (https://nodejs.org/en/)
Upgrade with npm
npm install -g npm
Note: some users still report issues updating npm with npm, but I haven't had that experience with v16+.
Download and run the latest MSI. The MSI will update your installed node and npm.
To update NPM, this worked for me:
Navigate in your shell to your node installation directory, eg C:\Program Files (x86)\nodejs
run npm install npm (no -g option)
Like some people, I needed to combine multiple answers, and I also needed to set a proxy.
This should work for anyone. I have zero desire to run an EXE file or MSI file .. uninstall/ reinstall, or manually delete files and folders. That is so 1999 :P
Run this to update NPM:
Run PowerShell as administrator
npm i -g npm // This works
I am not thinking this code actually upgrades your npm version below
Set-ExecutionPolicy Unrestricted -Scope CurrentUser -Force
npm install -g npm-windows-upgrade
npm-windows-upgrade
(courtesy of "Robert" answer)
Run this to update Node.js:
wget https://nodejs.org/download/release/latest/win-x64/node.exe -OutFile 'C:\Program Files (x86)\nodejs\node.exe' (courtesy of BrunoLM answer)
If you get `wget : Could not find a part of the path .... "**, see below ...scroll down. Reading Web Response... It's at least punching through the firewall /proxy (if you have one or have already ran the code get through ...
Otherwise
You might need to set your proxy
npm config set proxy "http://proxy.yourcorp.com:811" (yes, use quotes)
2 possible errors
It cannot find path of the path solution "where.exe node" (courtesy of Lonnie Best Answer)
E.g. if Node.js is NOT living in "Program Files (x86)" perhaps with where.exe, it is living in 'C:\Program Files\nodejs\node.exe'.
wget https://nodejs.org/download/release/latest/win-x64/node.exe -OutFile 'C:\Program Files\nodejs\node.exe'
Now perhaps it tries to upgrade but you get another error, "node.exe is being used by another process."
Close /shutdown other consoles .. command prompts and PowerShell windows, etc. Even if you're using npm in a command prompt, close it.
npm -v (3.10.8)
node -v ( v6.6.0)
DONE. I'm at the version that I want.
You can update your npm to the latest stable version with the following command:
npm install npm#latest -g
Use PowerShell to run it. This command doesn't need windows administrator privileges and you can verify the result with npm -v
You can use Chocolatey which is a package manager for windows (like apt-get for Debian Linux).
Install fresh (you might need to uninstall previously installed versions)
> choco install nodejs
Update to the latest version
> choco update nodejs
and for npm
> choco update npm
The previous answers will work installing a new version of Node.js (probably the best option), but if you have a dependency on a specific Node.js version then the following will work: "npm install npm -g". Verify by running npm -v before and after the command.
This works fine for me to update npm on Windows 7 x64:
Windows start
All Programs
Node.js
Node.js command prompt (alternative click)
Run as administrator
$ npm -g install npm
remove C:\Program Files\nodejs\npm.cmd the new npm will be at C:\Users\username\appdata\roaming\npm\npm.cmd
Hope this helps.
Open PowerShell as administrator.
To install a first time you can use this small script to download the latest msi and run it
$nodeLatest=((curl https://nodejs.org/download/release/latest/).Content | findstr x64.msi) -replace "<(.*?)>", "" -replace "\s+.+", "";
wget "https://nodejs.org/download/release/latest/$nodeLatest" -OutFile (join-path $env:TEMP node.msi); Start-Process (join-path $env:TEMP node.msi)
On future upgrades you can download just node.exe and update npm with
wget https://nodejs.org/download/release/latest/win-x64/node.exe -OutFile 'C:\Program Files\nodejs\node.exe'
npm i -g npm
You should now have the latest node and npm.
I went a little further and decided to implement a nvm for Windows.
https://github.com/brunolm/nvm
Install-Module -Name power-nvm
nvm install latest
nvm default latest
1. Installing latest npm version
npm install –g npm#latest
(You can type "npm –version" to check that)
2. Installing Node
a. Install node new version via following URL: https://nodejs.org/en/download/current/
Follow the default choices
b. Remove C:\Users\\AppData\Roaming\NPM
c. Remove C:\Users\\AppData\Roaming\npm-cache
Optionally:
d. (Delete node_modules folder in your current project folder)
e. npm cache verify
f. npm install
Use Upgrade npm on Windows
This is the official document for a user to upgrade npm on Windows!
Here is my screenshot!
For what it's worth, I had to combine several answers...
Uninstall Node.js in control panel Add/remove programs.
Delete directories, both C:\Program Files (x86)\nodejs\ and C:\Program Files\nodejs\ if they exist.
Install the latest version, http://nodejs.org/download/
How to Update Node.js:
Uninstall Node.js. Click the Start menu, type "Change or Remove a Program", click on the item shown, find Node.js in the list and uninstall it.
Delete directories, both C:\Program Files (x86)\nodejs\ and C:\Program Files\nodejs\ if they exist.
Install the latest, https://nodejs.org/en/download
The uninstall/delete/install seems unnecessary, but it often is and this will save your time.
These instructions come from Microsoft.
How to Update NPM:
https://www.npmjs.com/package/npm-windows-upgrade
This is the official documentation for upgrading npm on windows.
All was tested and working on Windows 10 (2017).
this is best tool to maintain version of NODE.Js i NVM
Node Version Manager (nvm) for Windows
but for Windows, with an installer. Download Now! This has always been a node version manager, not an io.js manager, so there is no back-support for io.js. However, node 4+ is supported.
For me, after totally uninstalling node 10.29, and then installing node 4.2.2, there remained a 10.29 node.exe file in my c:\windows folder.
I found this by using the following command:
where.exe node
The command returned:
C:\Windows\node.exe
C:\Program Files\nodejs\node.exe
So even though I had successfully installed version 4.2.2 via the msi executable, the command node -v would continue to report I was running version 10.29.
I resolved the problem by deleting this file:
C:\Windows\node.exe
Thereafter, node -v reported the upgraded version instead of the unwanted remnants of the prior version.
For NodeJS
Download required node version msi from here and install
for Npm
Run PowerShell as Administrator
Set-ExecutionPolicy Unrestricted -Scope CurrentUser -Force
npm install -g npm-windows-upgrade
npm-windows-upgrade
This works fine for me
Run Command Prompt as Administrator
Navigate to the folder containing nodejs (eg. C:\Program Files\nodejs)
Run Powershell -ExecutionPolicy Unrestricted
Run npm-windows-upgrade
This will show list of versions available to install. Just select your desired version by moving up/down key & Press Enter.
This'll update your npm
To check the current version of npm
Run npm --version
Command Prompt Screenshot
I was also facing similar issues. I followed below mentioned steps and it worked for me:
go to Windows > Start > Node.js
right click on Node.js command prompt
click on Run as administrator
ping registry.npmjs.org
npm view npm version
cd %ProgramFiles%\nodejs
npm install npm#latest
and npm updated successfully. Earlier I was trying for CMD and that was throwing error. may be some path issue that got resolved by running NodeJs Command Prompt. hope it'll work for you. try this.
OK guys, I read (tried on Windows) all the previous stuff and all of these answers have their own disadvantages.
For the best way to update Node.js (at least for me), go to https://nodejs.org/en/
Then download the last version and install it in same folder you installed the previous version in - 1 min and it's done. You don't need to remove any old files.
Then update npm typing in cmd: npm install --save latest-version
To install the updates, just download the installer from the Nodejs.org site and run it again. The new version of Node.js and NPM will replace the older versions.
The easiest way I found so far to update Node.js is using Chocolatey.
Use Chocolatey to install or update the latest version of Node.js on Windows:
Step 1: First, ensure that you already have Chocolatey installed. If not, use an administrative shell to install chocolatey through cmd.exe or PowerShell.exe. For more information, visit: https://chocolatey.org/docs/installation
Step 2: Install with cmd.exe. Run the following command:
#"%SystemRoot%\System32\WindowsPowerShell\v1.0\powershell.exe" -NoProfile -InputFormat None -ExecutionPolicy Bypass -Command "iex ((New-Object System.Net.WebClient).DownloadString('https://chocolatey.org/install.ps1'))" && SET "PATH=%PATH%;%ALLUSERSPROFILE%\chocolatey\bin"
To install with PowerShell.exe, visit: https://chocolatey.org/docs/installation
Step 3: Install or Update with following commands on cmd.exe (on administrative mode)
To Install Node.js: cinst nodejs.install
To Update Node.js: cup nodejs.install
follow these steps for window 10 or window 8
press WIN + R and type cmd and enter
npm i -g npm#next
npm i -g npm#next OR npm i -g node#{version}
Remove environment path C:\Program Files\nodejs from envrionment variable PATH.
type refreshenv in cmd
Now you will have your new version which you installed.
Note: If you don't remove path. You will see the previous version of node.
PowerShell does not execute npm directly, so I suggest using
.\npm install -g npm-windows-upgrade
.\npm-windows-upgrade
And it failed with:
You wanted to install npm 6.1.0, but the installed version is 3.10.10.
A common reason is an attempted "npm install npm" or "npm upgrade npm". As of today, the only solution is to completely uninstall and then reinstall Node.js. For a small tutorial, please see http://aka.ms/fix-npm-upgrade (dead link).
Please consider reporting your trouble to npm-windows-upgrade.
I followed josh3737 and installed the latest MSI from the Node.js homepage.
But I had the additional problem that I still had the old version of Node.js and npm on the command line. The problem was caused by the new installation, and that it was installed into
C:\Program Files (x86)\nodejs\
instead of the previous installation in
C:\Program Files\nodejs\
The new installation added the new directory into my path variable after the old one. So the old installation was still the active one in the path. After removing C:\Program Files\nodejs\ from system path and C:\Users\...\AppData\Roaming\npm from user path and restarting the command line the new installation was active.
Maybe the least path was a local problem that has nothing to do with the new installation. I had two links to AppData\Roaming\npm in it. And maybe this can also be fixed by first uninstalling Node.js and installing the new version afterwards.
You can use these commands:
npm cache clean
npm update -g [package....]
If you are upgrading from a previous version of node, then you will want to update all existing global packages.
You can also specify the package name to be updated.
This might help someone. Neither "npm-windows-upgrade" nor the installer alone did it for me. Powershell was still using an older version of node and npm.
So this is what I did (worked for me):
1. Download the latest installer from nodejs.org. Install node. It will update your node; everywhere (Powershell, cmd etc.).
2. Install the npm-windows-upgrade package (npm install -g npm-windows-upgrade) and run npm-windows-upgrade.
I didn't uninstall anything and didn't set any paths.
In my case, I discovered that I had two copies of Node.js installed. One under "C:\Program Files\nodejs" and another under "C:\Program Files (x86)\nodejs".
This is what worked for me.
Open a local folder other than the one in which nodejs is installed.
Install npm in that folder with command npm install npm
Navigate to the folder containing node js. (C:\Program Files\nodejs\node_modules)
Delete the npm folder and replace it with the npm and bin folders in the local folder.
Run npm -v. Now you would get updated version for npm.
Note: I tried installing npm directly in "C:\Program Files\nodejs\node_modules" but it created errors.
Start
Search for windows powershell
Right click and run as administrator
Type: where.exe node (returns the path of node.exe in your system. Copy this)
wget https://nodejs.org/download/release/latest/win-x64/node.exe -OutFile 'PATH-OF-NODE.EXE_WHICH_YOU_COPIED_JUST_NOW'
To check if it has worked, go to your Git bash/Normal command prompt and type: node -v
Here you can find the current version of node: https://nodejs.org/en/blog/release/

Resources