📜 ⬆️ ⬇️

Chocolatey - apt-get for Windows

Chocolatey is a package manager in the Windows environment by analogy with apt-get in the Linux World.



I started using it due to development on Node.js under Nodester. I would like to regularly update the node, git, dropbox, and the same skype, while not bothering with downloading msi installers and installations, but just to update with one command:
')
cup all

It is possible to upgrade all packages . General list of available commands in the wiki. Unfortunately, there is no way to remove packages .

So, as work constantly requires access to the console, git, node, jade. I would like to slightly illustrate the work with Chocolatey in the context (by example) of the preparation for the development under Nodester.

Installation requirements:

Windows XP / Vista / 7/2003/2008
.NET Framework 4.0
Powershell 2.0

It is installed simply by executing such a simple command (in cmd.exe in PowerShell is not processed):

@powershell -NoProfile -ExecutionPolicy unrestricted -Command "iex ((new-object net.webclient).DownloadString('http://bit.ly/psChocInstall'))"

Chocolatey installation process

After that, it is automatically installed in C: \ Chocolatey, in C: \ Chocolatey \ libs there will be descriptions of packages, libraries. The main modules of programs are installed by default in Program Files (x86).

All the basic and necessary for the developer, the packages are present . Interpreted languages ​​such as PHP , Ruby , Python , Node.js. DB - MySQL , MongoDB , SQLite . Version Control Git , Mercurial, SVN . Notepad ++, Sublime. Calibre to handle books under the Kindle.

1. Installing the Node.js package with npm

cinst nodejs.install

This command is similar to the following.

chocolatey install nodejs.install



True, the console will have to close and reopen, so that the recorded paths in the path become available.



2. When the node is installed it is already possible to develop, install modules through the package manager. That bag for Nodster



3. Without Git-a on Nodester, it will not be possible to deploy it, so install it using Chocolatey



Here is a list of what I have additionally installed.

cinst Console2
cinst putty
cinst curl
cinst Wget


We try putty, the command opens the program window and we look at the fact that git was installed successfully (I remind you that you have to close the console and open it again).



4. Here we see that we can freely contact Nodester



Next is the routine process, the installation on the local machine via npm required in the project modules, such as expressjs, jade, testing on a local web server that loads the node. All this business is conducted in git, kommititsya then push in turnips of nodester is made. On nodester-e ( list of commands ) you will also need to install npm modules through nodester npm install appname.

Chocolatey is not suitable for everything. The very ideology of Windows and applications created for the platform tends to assume that they themselves should go into autoload and be updated at every opportunity without permission. So, in packages there is Chrome, but we know about GoogleUpdater.exe which updates everything already. So, also about Notepad ++ which itself can crawl for updates. Skype and you can update yourself. However, if you initially put everything in chocolate, a quick update with one team will be fun, especially if it is not related to GUI tools.

Finally I will attach a video clip from the office. the site



UPD.

The comments asked to add the Slik Subversion (SVN) package. I think it would be useful to illustrate how easy it is. Also clarified the principle of the "chocolate".

The main description and installation script for the simplest case. All the packages you can build yourself, here are examples .

1. Create a description file C: \ sliksvn \ sliksvn.nuspec with the appropriate text ( original disc ):

 <?xml version="1.0"?> <package xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema"> <metadata> <id>sliksvn</id> <title>SlikSVN</title> <version>1.7.4</version> <authors>Slik Company</authors> <owners>anatooly</owners> <summary>Slik subversion reliable version control starts here</summary> <description>We provide a standalone command line Subversion package for Windows. The installer contains all command line tools (svn, svnadmin, svnsync, svnserve, svnmucc, etc.) but no application bindings nor Apache modules. The tools are fully side-by-side compatible with other packages. Ideal for automated build and deploy scripts</description> <projectUrl>http://www.sliksvn.com/</projectUrl> <tags>sliksvn svn subversion</tags> <copyright>Slik Company</copyright> <requireLicenseAcceptance>false</requireLicenseAcceptance> </metadata> </package> 


2. Then create the installation script C: \ sliksvn \ tools \ chocolateyInstall.ps1

try {

Install-ChocolateyPackage 'sliksvn' 'msi' '/quiet' 'www.sliksvn.com/pub/Slik-Subversion-1.7.4-win32.msi' 'http://www.sliksvn.com/pub/Slik-Subversion-1.7.4-x64.msi'

Write-ChocolateySuccess 'SlikSVN'
} catch {
Write-ChocolateyFailure 'SlikSVN' "$($_.Exception.Message)"
throw
}


From the code it becomes clear. What is downloaded from the office. The site is either 32-bit or 64-bit installer and will be placed in silent mode without distracting questions.

3. Add. installation file (may be missing), but in this case it’s not important C: \ sliksvn \ tools \ install.ps1

param($installPath, $toolsPath, $package, $project)

Write-Host 'This is not a package with dlls to reference in it.'
Write-Host 'Please install using chocolatey'
Write-Host "To get chocolatey just run 'Install-Package chocolatey' followed by 'Initialize-Chocolatey'"
Write-Host 'chocolatey install sliksvn'
write-host 'Removing this package...'
uninstall-package sliksvn -ProjectName $project.Name


4. Build a package. It can be collected NuGet th. Register access to it in the path, or contact through the full path. It lies in C: \ Chocolatey \ chocolateyInstall \ NuGet.exe

> cd C: \ sliksvn
> nuget pack

Then we get the C: \ sliksvn \ sliksvn.1.7.4.nupkg local package. You can already install from it, check the cinst sliksvn -source C: \ sliksvn (the path is only the path to the folder where the package is located, without its name). Installed locally. Then you can upload the package to the site. It works postmoderation mode, so that the package will be visible immediately and becomes available through cinst sliksvn.

How does everything work when you install the package? When installing, everything that is packaged in the nupkg package - installation scripts, description, and other files, binary archives (there are many interesting examples of what can be there) goes to the C: \ Chocolatey \ lib \ NAME_PACKET folder, but the actions specified in the script, in our case, a silent installation is performed by default, that is, SlikSVN I have a 64-bit system, which means it is installed in C: \ Program Files \ SlikSVN \ and is itself written in the path. But in fact, the installation can be any unpacking from its own archive, which will be included in the package, or any other actions with its incoming libraries. It all depends on the fantasy.

How to remove it? SlikSVN itself through Install-Uninstall, like any standard installed program, and from C: \ Chocolatey \ lib \ PACKET_NAME by hand.

Update 2012-08-15 :

In recent versions, the removal of packages via chocolatey uninstall has already appeared. The command deletes the contents of the package from C: \ Chocolatey \ lib \ package name, that is, utilities that are installed by unpacking into this folder are completely removed. The fact that it was installed in the system and in the Program Files is not moved.

The list of installed, as it would be logical to assume for chocolatey list of packages - no. But this can be easily fixed, as an option with such a hack:

 diff --git "a/c:\\Chocolatey\\chocolateyInstall\\functions\\Chocolatey-List.ps1" "b/c:\\Chocolatey\\chocolateyInstall\\functions\\Chocolatey-List.ps1" index 67c2ecc..aa67027 100644 --- "a/c:\\Chocolatey\\chocolateyInstall\\functions\\Chocolatey-List.ps1" +++ "b/c:\\Chocolatey\\chocolateyInstall\\functions\\Chocolatey-List.ps1" @@ -15,7 +15,12 @@ param( $parameters = "list" if ($selector -ne '') { $parameters = "$parameters ""$selector""" - } + } else { + $packageFolders = Get-ChildItem $nugetLibPath | sort name + $packages = $packageFolders -replace "(\.\d{1,})+"|gu + Write-Host $packages + exit + } if ($allVersions -eq $true) { Write-Debug "Showing all versions of packages" 

Now for the chocolatey list we get:

7zip 7zip.install chocolatey Console2 curl foobar2000 git git.install miranda msysgit nodejs.install notepadplusplus notepadplusplus.install php php5-dev putty sliksvn sublimetext2 warmup Wget

Source: https://habr.com/ru/post/143996/


All Articles