How to install NuGet from command line on linux

LinuxNuget

Linux Problem Overview


I need to install NuGet on Linux based machine.When am using the following command in Windows machine it works fine.

nuget install packages.config

But I am unable to do this with linux machine, how to achieve this?

Linux Solutions


Solution 1 - Linux

Once you've followed the (somewhat annoying) install steps to get .Net core installed and the apt repo setup from https://www.microsoft.com/net/core, you can just do this:

sudo apt install nuget

and you'll have a working nuget on your local machine:

$ cat /etc/issue
Ubuntu 16.04.1 LTS \n \l

$ nuget
NuGet Version: 2.8.7.0
usage: NuGet <command> [args] [options] 
Type 'NuGet help <command>' for help on a specific command.

Notice that as of the time of writing do not run nuget update -self, as although it will successfully install a more recent version of nuget, that version won't actually run.

If you do break it though, you can always just blow it away and reinstall:

sudo apt remove nuget
sudo apt install nuget

Solution 2 - Linux

Install mono, then download nuget:

sudo apt-get install mono-complete
wget https://dist.nuget.org/win-x86-commandline/latest/nuget.exe

After then run it using mono nuget.exe.

Solution 3 - Linux

nuget apt package doesn't really work on linux, and exe's are for windows. If you want to run nuget the easiest thing is to use mono wrapper.

sudo apt-get install mono-complete
//download nuget.exe
mono nuget.exe install

Solution 4 - Linux

In case you want to use nuget with WSL2, the steps are as follows.

  1. Download nuget.exe through wget https://dist.nuget.org/win-x86-commandline/latest/nuget.exe

  2. Create a bash file called nuget:

> nuget
# Or
vi nuget
  1. Edit the file with the content below (vim nuget, then i):
# Edit the file with - make sure to add the correct path to nuget.exe file
'nuget.exe' $@ &
  1. Make it executable.
# Make it executable
chmod +x nuget
  1. Add to the $PATH environment variable
# Edit .bashrc
vi .bashrc
  1. Insert export PATH=/path/to/nuget-folder:$PATH in the .bashrc file.

Solution 5 - Linux

Follow the Microsoft instructions for installing Nuget on Linux:

  1. Install Mono 4.4.2 or later.

  2. Execute the following command at a shell prompt (Bash):

    # Download the latest stable `nuget.exe` to `/usr/local/bin` 
    sudo curl -o /usr/local/bin/nuget.exe https://dist.nuget.org/win-x86-commandline/latest/nuget.exe
    
  3. Create an alias by adding the following script to the appropriate file for your OS (typically ~/.bash_aliases or ~/.bash_profile)(Bash):

    # Create as alias for nuget
    alias nuget="mono /usr/local/bin/nuget.exe"
    
  4. Reload the shell. Test the installation by entering nuget with no parameters. NuGet CLI help should display.

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
Questionuser3610920View Question on Stackoverflow
Solution 1 - LinuxDougView Answer on Stackoverflow
Solution 2 - LinuxolegzView Answer on Stackoverflow
Solution 3 - LinuxWarren ParadView Answer on Stackoverflow
Solution 4 - LinuxAlexzView Answer on Stackoverflow
Solution 5 - LinuxGary BarrettView Answer on Stackoverflow