{"id":31672,"date":"2026-12-02T22:07:07","date_gmt":"2026-12-02T22:07:07","guid":{"rendered":"https:\/\/www.devopsschool.com\/blog\/?p=31672"},"modified":"2026-12-02T22:07:07","modified_gmt":"2026-12-02T22:07:07","slug":"how-to-download-package-from-nexus-using-curl","status":"publish","type":"post","link":"https:\/\/www.devopsschool.com\/blog\/how-to-download-package-from-nexus-using-curl\/","title":{"rendered":"How to download package from Nexus using curl?"},"content":{"rendered":"\n<p class=\"wp-block-paragraph\">With curl you can download a file from Sonatype Nexus Repository 3 in two ways. If you know the exact path, request <code>\/repository\/&lt;repo&gt;\/&lt;path&gt;<\/code>. If you only know the coordinates, call the REST search API at <code>\/service\/rest\/v1\/search\/assets\/download<\/code> to fetch the latest matching file. This guide explains the gist examples above, fixes the ones that are broken or meant for the retired Nexus 2 API, and gives you scripts that work on current Nexus 3 servers.<\/p>\n\n\n\n<script src=\"https:\/\/gist.github.com\/devops-school\/33da285dfeaa1d124571f1c1cc8ca086.js\"><\/script>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h2 class=\"wp-block-heading\">Three ways Nexus 3 serves a file<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">The examples above mix several Nexus endpoints, and some of them belong to Nexus 2. Before choosing a command, decide which situation you are in.<\/p>\n\n\n\n<figure class=\"wp-block-table\"><table><thead><tr><th>You know<\/th><th>Endpoint<\/th><th>Best for<\/th><\/tr><\/thead><tbody><tr><td>The exact file path<\/td><td><code>\/repository\/&lt;repo&gt;\/&lt;path&gt;<\/code><\/td><td>Releases, raw files, fixed versions<\/td><\/tr><tr><td>Coordinates only (group, artifact, base version)<\/td><td><code>\/service\/rest\/v1\/search\/assets\/download<\/code><\/td><td>Latest release or latest snapshot in CI<\/td><\/tr><tr><td>Nothing; you want everything<\/td><td><code>\/service\/rest\/v1\/assets?repository=&lt;repo&gt;<\/code><\/td><td>Backups and migrations (paginated)<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Note:<\/strong> URLs containing <code>\/service\/local\/artifact\/maven\/redirect<\/code> or <code>\/service\/local\/artifact\/maven\/content<\/code> belong to the <strong>Nexus 2<\/strong> REST API. Nexus Repository 3 does not have them, so the PowerShell script and the first <code>wget<\/code> line above return 404 on a Nexus 3 server.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Prerequisites and safe credentials<\/h2>\n\n\n\n<ul class=\"wp-block-list\">\n<li>A Nexus 3 user with read and browse privileges on the repository, for example <code>nx-repository-view-maven2-maven-releases-read<\/code> and <code>-browse<\/code>. If anonymous access is enabled and the repository allows reads, you do not need credentials.<\/li>\n\n\n<li><code>curl<\/code>, plus <code>jq<\/code> for parsing JSON (<code>apt install jq<\/code> or <code>dnf install jq<\/code>).<\/li>\n\n\n<li>The base URL of your server. On Nexus 3 the default context path is <code>\/<\/code>, so URLs look like <code>https:\/\/nexus.example.com\/repository\/...<\/code>. You only need <code>\/nexus\/...<\/code> if an administrator configured that context path.<\/li>\n<\/ul>\n\n\n\n<p class=\"wp-block-paragraph\">Passing <code>-u user:password<\/code> on the command line exposes the password in shell history and in the process list. The hard-coded <code>Authorization: Basic YWRtaW46YWRtaW4=<\/code> header above has the same problem: Base64 is an encoding, not encryption, and that value decodes to <code>admin:admin<\/code>. A <code>.netrc<\/code> file is a safer choice:<\/p>\n\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-1\" data-shcb-language-name=\"PHP\" data-shcb-language-slug=\"php\"><span><code class=\"hljs language-php\">cat &gt; ~\/.netrc &lt;&lt;<span class=\"hljs-string\">'EOF'<\/span>\nmachine nexus.example.com\nlogin ci-reader\npassword change-me\nEOF\nchmod <span class=\"hljs-number\">600<\/span> ~\/.netrc\n\nexport NEXUS_URL=https:<span class=\"hljs-comment\">\/\/nexus.example.com<\/span><\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-1\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">PHP<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">php<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\n\n\n<p class=\"wp-block-paragraph\">With this file in place, <code>curl -n<\/code> (<code>--netrc<\/code>) sends the credentials automatically. All the examples below use <code>-n<\/code>.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Download a file by its direct URL<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">Every asset in Nexus 3 has a URL of the form <code>&lt;base&gt;\/repository\/&lt;repo-name&gt;\/&lt;path&gt;<\/code>. In Maven repositories the path follows the standard layout: the dots in the groupId become slashes, followed by the artifactId, the version, and then the file name.<\/p>\n\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-2\" data-shcb-language-name=\"PHP\" data-shcb-language-slug=\"php\"><span><code class=\"hljs language-php\"><span class=\"hljs-comment\"># Maven release: com.example:my-app:1.2.0 (jar)<\/span>\ncurl -fL -n -O \\\n  <span class=\"hljs-string\">\"$NEXUS_URL\/repository\/maven-releases\/com\/example\/my-app\/1.2.0\/my-app-1.2.0.jar\"<\/span>\n\n<span class=\"hljs-comment\"># Raw repository: file uploaded to directory 'devops'<\/span>\ncurl -fL -n -o devops<span class=\"hljs-number\">-1.0<\/span><span class=\"hljs-number\">.0<\/span><span class=\"hljs-number\">.0<\/span>.zip \\\n  <span class=\"hljs-string\">\"$NEXUS_URL\/repository\/devopsrepo\/devops\/devops-1.0.0.0.zip\"<\/span><\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-2\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">PHP<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">php<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\n\n\n<ul class=\"wp-block-list\">\n<li><code>-f<\/code> makes curl exit with an error on HTTP 4xx\/5xx instead of saving the error page as your artifact.<\/li>\n\n\n<li><code>-L<\/code> follows redirects.<\/li>\n\n\n<li><code>-O<\/code> keeps the remote file name. <code>-o &lt;file&gt;<\/code> sets a name of your choice.<\/li>\n\n\n<li><code>--output-dir<\/code>, used above, requires curl 7.73.0 or later. On older curl, use <code>-o \/some-dir\/file.zip<\/code> instead.<\/li>\n<\/ul>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Note:<\/strong> Maven snapshots are stored with timestamped file names such as <code>my-app-1.0-20240101.120000-3.jar<\/code>, so you usually cannot guess their direct URL. For snapshots, use the search API in the next section.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Download the latest version with the search API<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">The <code>search\/assets\/download<\/code> endpoint runs a search and answers with a 302 redirect to the matching asset, so a single <code>curl -L<\/code> downloads the file. This is the cleanest replacement for <code>Download.sh<\/code> above:<\/p>\n\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-3\" data-shcb-language-name=\"JavaScript\" data-shcb-language-slug=\"javascript\"><span><code class=\"hljs language-javascript\">curl -fL -n -G -o my-artifact.jar \\\n  <span class=\"hljs-string\">\"$NEXUS_URL\/service\/rest\/v1\/search\/assets\/download\"<\/span> \\\n  -d repository=maven-snapshots \\\n  -d maven.groupId=my.group.id \\\n  -d maven.artifactId=my-artifact \\\n  -d maven.baseVersion=<span class=\"hljs-number\">1.0<\/span>-SNAPSHOT \\\n  -d maven.extension=jar \\\n  -d maven.classifier=jar-<span class=\"hljs-keyword\">with<\/span>-dependencies \\\n  -d sort=version \\\n  -d direction=desc<\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-3\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">JavaScript<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">javascript<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\n\n\n<p class=\"wp-block-paragraph\"><code>-G<\/code> appends the <code>-d<\/code> values to the URL as a query string, so you do not need <code>-X GET<\/code>. If more than one asset matches, the endpoint returns <strong>400 Bad Request<\/strong>. Adding <code>sort<\/code> makes it pick the first result instead. Make the filters specific (extension and classifier) so that a POM or a sources jar is never chosen by mistake. To get the newest release, drop <code>maven.baseVersion<\/code>, point <code>repository<\/code> at your releases repository, and keep <code>sort=version<\/code>.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">When you also want to verify the file, call <code>search\/assets<\/code> instead. It returns JSON that contains the download URL and the checksums:<\/p>\n\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-4\" data-shcb-language-name=\"JavaScript\" data-shcb-language-slug=\"javascript\"><span><code class=\"hljs language-javascript\">resp=$(curl -fsSL -n -G <span class=\"hljs-string\">\"$NEXUS_URL\/service\/rest\/v1\/search\/assets\"<\/span> \\\n  -d repository=maven-releases \\\n  -d maven.groupId=com.example \\\n  -d maven.artifactId=my-app \\\n  -d version=<span class=\"hljs-number\">1.2<\/span><span class=\"hljs-number\">.0<\/span> \\\n  -d maven.extension=jar)\n\nurl=$(jq -r <span class=\"hljs-string\">'.items&#91;0].downloadUrl'<\/span> &lt;&lt;&lt;<span class=\"hljs-string\">\"$resp\"<\/span>)\nsha1=$(jq -r <span class=\"hljs-string\">'.items&#91;0].checksum.sha1'<\/span> &lt;&lt;&lt;<span class=\"hljs-string\">\"$resp\"<\/span>)\n\ncurl -fsSL -n -o my-app.jar <span class=\"hljs-string\">\"$url\"<\/span>\necho <span class=\"hljs-string\">\"$sha1  my-app.jar\"<\/span> | sha1sum -c -<\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-4\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">JavaScript<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">javascript<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-5\" data-shcb-language-name=\"CSS\" data-shcb-language-slug=\"css\"><span><code class=\"hljs language-css\"><span class=\"hljs-selector-tag\">my-app<\/span><span class=\"hljs-selector-class\">.jar<\/span>: <span class=\"hljs-selector-tag\">OK<\/span><\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-5\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">CSS<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">css<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\n\n\n<h2 class=\"wp-block-heading\">Download an entire repository (corrected script)<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\"><code>DownloadAll.sh<\/code> above has the right idea: page through <code>\/service\/rest\/v1\/assets<\/code> with <code>continuationToken<\/code>, then download each <code>downloadUrl<\/code>. It breaks in practice, though. <code>$curFolder<\/code> is never set, so after the first file the script <code>cd<\/code>s into your home directory. The path stripping only works for <code>http:\/\/host:port<\/code> URLs, and <code>-k<\/code> turns off TLS verification. The version below fixes these problems and uses <code>jq<\/code> for all JSON parsing:<\/p>\n\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-6\" data-shcb-language-name=\"PHP\" data-shcb-language-slug=\"php\"><span><code class=\"hljs language-php\"><span class=\"hljs-comment\">#!\/usr\/bin\/env bash<\/span>\n<span class=\"hljs-comment\"># Usage: NEXUS_URL=https:\/\/nexus.example.com REPO=maven-releases .\/nexus-export.sh<\/span>\nset -euo pipefail\n\n: <span class=\"hljs-string\">\"${NEXUS_URL:?set NEXUS_URL}\"<\/span>\n: <span class=\"hljs-string\">\"${REPO:?set REPO}\"<\/span>\nOUT_DIR=<span class=\"hljs-string\">\".\/${REPO}\"<\/span>\n<span class=\"hljs-keyword\">LIST<\/span>=<span class=\"hljs-string\">\"${REPO}-artifacts.txt\"<\/span>\n: &gt; <span class=\"hljs-string\">\"$LIST\"<\/span>                      <span class=\"hljs-comment\"># start with an empty list on every run<\/span>\n\n<span class=\"hljs-comment\"># 1. Collect all download URLs, following pagination<\/span>\ntoken=<span class=\"hljs-string\">\"\"<\/span>\n<span class=\"hljs-keyword\">while<\/span> :; <span class=\"hljs-keyword\">do<\/span>\n  url=<span class=\"hljs-string\">\"${NEXUS_URL}\/service\/rest\/v1\/assets?repository=${REPO}\"<\/span>\n  &#91; -n <span class=\"hljs-string\">\"$token\"<\/span> ] &amp;&amp; url=<span class=\"hljs-string\">\"${url}&amp;continuationToken=${token}\"<\/span>\n  resp=$(curl -fsSL -n -H <span class=\"hljs-string\">'Accept: application\/json'<\/span> <span class=\"hljs-string\">\"$url\"<\/span>)\n  jq -r <span class=\"hljs-string\">'.items&#91;].downloadUrl'<\/span> &lt;&lt;&lt;<span class=\"hljs-string\">\"$resp\"<\/span> &gt;&gt; <span class=\"hljs-string\">\"$LIST\"<\/span>\n  token=$(jq -r <span class=\"hljs-string\">'.continuationToken \/\/ empty'<\/span> &lt;&lt;&lt;<span class=\"hljs-string\">\"$resp\"<\/span>)\n  &#91; -z <span class=\"hljs-string\">\"$token\"<\/span> ] &amp;&amp; <span class=\"hljs-keyword\">break<\/span>\ndone\n<span class=\"hljs-keyword\">echo<\/span> <span class=\"hljs-string\">\"Found $(wc -l &lt; \"<\/span>$LIST<span class=\"hljs-string\">\") assets\"<\/span>\n\n<span class=\"hljs-comment\"># 2. Download each asset, keeping the repository layout<\/span>\nfail=<span class=\"hljs-number\">0<\/span>\n<span class=\"hljs-keyword\">while<\/span> IFS= read -r dl; <span class=\"hljs-keyword\">do<\/span>\n  rel=<span class=\"hljs-string\">\"${dl#*\/repository\/${REPO}\/}\"<\/span>\n  dest=<span class=\"hljs-string\">\"${OUT_DIR}\/${rel}\"<\/span>\n  mkdir -p <span class=\"hljs-string\">\"$(dirname \"<\/span>$dest<span class=\"hljs-string\">\")\"<\/span>\n  code=$(curl -sSL -n -o <span class=\"hljs-string\">\"$dest\"<\/span> -w <span class=\"hljs-string\">'%{http_code}'<\/span> <span class=\"hljs-string\">\"$dl\"<\/span>) || <span class=\"hljs-keyword\">true<\/span>\n  <span class=\"hljs-keyword\">if<\/span> &#91; <span class=\"hljs-string\">\"$code\"<\/span> = <span class=\"hljs-string\">\"200\"<\/span> ]; then\n    <span class=\"hljs-keyword\">echo<\/span> <span class=\"hljs-string\">\"OK    $rel\"<\/span>\n  <span class=\"hljs-keyword\">else<\/span>\n    <span class=\"hljs-keyword\">echo<\/span> <span class=\"hljs-string\">\"FAIL  $rel (HTTP $code)\"<\/span> &gt;&amp;<span class=\"hljs-number\">2<\/span>\n    rm -f <span class=\"hljs-string\">\"$dest\"<\/span>; fail=$((fail+<span class=\"hljs-number\">1<\/span>))\n  fi\ndone &lt; <span class=\"hljs-string\">\"$LIST\"<\/span>\n\n<span class=\"hljs-keyword\">echo<\/span> <span class=\"hljs-string\">\"Done with $fail failures\"<\/span>\n&#91; <span class=\"hljs-string\">\"$fail\"<\/span> -eq <span class=\"hljs-number\">0<\/span> ]<\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-6\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">PHP<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">php<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\n\n\n<ul class=\"wp-block-list\">\n<li><code>jq -r &#039;.items[].downloadUrl&#039;<\/code> replaces the four <code>sed<\/code> passes and the temporary files.<\/li>\n\n\n<li><code>.continuationToken \/\/ empty<\/code> prints nothing when the token is <code>null<\/code>, which ends the loop on the last page.<\/li>\n\n\n<li><code>${dl#*\/repository\/${REPO}\/}<\/code> strips everything up to the repository name, so the script works with HTTP or HTTPS, with or without a port, and with any context path.<\/li>\n\n\n<li><code>-w &#039;%{http_code}&#039;<\/code> reports the status code directly, so there is no need to write a header file and parse it.<\/li>\n<\/ul>\n\n\n\n<h2 class=\"wp-block-heading\">Downloading on Windows with PowerShell<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">The <code>download.ps1<\/code> script above calls the Nexus 2 <code>redirect<\/code> endpoint and then parses the redirect out of the response body. On Nexus 3, call the search download endpoint and let <code>Invoke-WebRequest<\/code> follow the redirect:<\/p>\n\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-7\" data-shcb-language-name=\"PHP\" data-shcb-language-slug=\"php\"><span><code class=\"hljs language-php\">$nexus   = <span class=\"hljs-string\">\"https:\/\/nexusrepo.example.com\"<\/span>\n$pair    = <span class=\"hljs-string\">\"{0}:{1}\"<\/span> -f $env:NEXUS_USER, $env:NEXUS_PASS\n$token   = &#91;Convert]::ToBase64String(&#91;Text.Encoding]::UTF8.GetBytes($pair))\n$headers = @{ Authorization = <span class=\"hljs-string\">\"Basic $token\"<\/span> }\n\n$query = <span class=\"hljs-string\">\"repository=my-snapshot&amp;maven.groupId=my.group.id&amp;maven.artifactId=my.artifact.id\"<\/span> +\n         <span class=\"hljs-string\">\"&amp;maven.baseVersion=1.10.0-SNAPSHOT&amp;maven.classifier=win32.win32.x86_64\"<\/span> +\n         <span class=\"hljs-string\">\"&amp;maven.extension=zip&amp;sort=version\"<\/span>\n\nInvoke-WebRequest -Uri <span class=\"hljs-string\">\"$nexus\/service\/rest\/v1\/search\/assets\/download?$query\"<\/span> `\n  -Headers $headers -OutFile <span class=\"hljs-string\">\"MyApp.zip\"<\/span><\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-7\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">PHP<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">php<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\n\n\n<p class=\"wp-block-paragraph\"><strong>Note:<\/strong> In PowerShell 7, add <code>-PreserveAuthorizationOnRedirect<\/code> so that the Authorization header is still sent after the 302. In Windows PowerShell 5.1, <code>curl<\/code> is an alias for <code>Invoke-WebRequest<\/code>. Type <code>curl.exe<\/code> to run the real curl that ships with current Windows versions.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Corrections to the examples above<\/h2>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong><code>nexus-download.sh<\/code> starts with uploads.<\/strong> The first two <code>curl -X POST ...\/components<\/code> commands publish a file to a raw repository; they do not download anything. Keep them as an upload step, and remove the trailing space in <code>-F &#039;raw.directory=devops &#039;<\/code>. Otherwise the directory name may include the space.<\/li>\n\n\n<li><strong>Nexus 2 endpoints.<\/strong> <code>download.ps1<\/code> and the first <code>wget<\/code> line use <code>\/service\/local\/artifact\/maven\/...<\/code>, which does not exist in Nexus 3. Use <code>\/service\/rest\/v1\/search\/assets\/download<\/code> instead.<\/li>\n\n\n<li><strong>Fragile JSON parsing in <code>Download.sh<\/code>.<\/strong> The <code>grep -Po<\/code> pattern depends on the exact whitespace of the JSON output. If it matches more than one URL, <code>xargs<\/code> downloads all of them into the same file. Use <code>jq<\/code> or the <code>search\/assets\/download<\/code> endpoint.<\/li>\n\n\n<li><strong><code>\/nexus\/<\/code> in URLs.<\/strong> That was the default path in Nexus 2. On Nexus 3 it is only correct if your server was configured with that context path.<\/li>\n\n\n<li><strong><code>--output-dir<\/code><\/strong> needs curl 7.73.0 or later.<\/li>\n\n\n<li><strong>wget with credentials.<\/strong> <code>--password=...<\/code> stores the password in shell history. Use <code>--ask-password<\/code>, or put the credentials in <code>~\/.wgetrc<\/code> with restricted permissions.<\/li>\n<\/ul>\n\n\n\n<h2 class=\"wp-block-heading\">Troubleshooting common errors<\/h2>\n\n\n\n<figure class=\"wp-block-table\"><table><thead><tr><th>Symptom<\/th><th>Likely cause<\/th><th>Fix<\/th><\/tr><\/thead><tbody><tr><td>HTTP 401<\/td><td>Wrong credentials, or anonymous access disabled<\/td><td>Check <code>.netrc<\/code> and test with <code>curl -n -I &lt;url&gt;<\/code><\/td><\/tr><tr><td>HTTP 403<\/td><td>User lacks read\/browse privilege on the repository<\/td><td>Grant <code>nx-repository-view-&lt;format&gt;-&lt;repo&gt;-read<\/code> and <code>-browse<\/code><\/td><\/tr><tr><td>HTTP 404<\/td><td>Wrong repository name or path, or wrong <code>\/nexus<\/code> context path<\/td><td>Copy the path from the asset in the Nexus UI (Browse view)<\/td><\/tr><tr><td>HTTP 400 from <code>search\/assets\/download<\/code><\/td><td>Several assets match the search<\/td><td>Add <code>sort=version<\/code> or more specific filters<\/td><\/tr><tr><td>Downloaded file is tiny HTML or JSON<\/td><td>Error page saved because <code>-f<\/code> was missing, or redirect not followed<\/td><td>Use <code>curl -fL<\/code>, then check the file with <code>file &lt;name&gt;<\/code><\/td><\/tr><tr><td><code>SSL certificate problem<\/code><\/td><td>Internal CA not trusted<\/td><td>Use <code>--cacert ca.pem<\/code> rather than <code>-k<\/code><\/td><\/tr><tr><td><code>option --output-dir: is unknown<\/code><\/td><td>curl older than 7.73.0<\/td><td>Use <code>-o dir\/filename<\/code><\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<h2 class=\"wp-block-heading\">Frequently asked questions<\/h2>\n\n\n\n<h3 class=\"wp-block-heading\">How do I download an artifact from Nexus 3 with curl?<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">Request <code>&lt;nexus-url&gt;\/repository\/&lt;repo&gt;\/&lt;path-to-file&gt;<\/code> with <code>curl -fL -O<\/code>, adding credentials with <code>-n<\/code> (<code>.netrc<\/code>) or <code>-u<\/code> if anonymous access is disabled. In the Nexus UI, the Browse view shows the exact path of each asset.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">How do I download the latest version of an artifact from Nexus?<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">Call <code>\/service\/rest\/v1\/search\/assets\/download<\/code> with the repository, Maven coordinates and <code>sort=version<\/code>, and use <code>curl -L<\/code> so that curl follows the 302 redirect to the newest matching file. For snapshots, filter by <code>maven.baseVersion<\/code>, for example <code>1.0-SNAPSHOT<\/code>.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Why does search\/assets\/download return 400 Bad Request?<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">The search matched more than one asset, for example the jar, the POM and the sources jar. Add <code>maven.extension<\/code> and <code>maven.classifier<\/code> filters, or add a <code>sort<\/code> parameter so that the endpoint picks the first result.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Can I use wget instead of curl to download from Nexus?<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">Yes. Use the same <code>\/repository\/&lt;repo&gt;\/&lt;path&gt;<\/code> URL with <code>wget --user=&lt;name&gt; --ask-password &lt;url&gt;<\/code>. The Nexus 2 <code>\/service\/local\/artifact\/maven\/content<\/code> URLs will not work on Nexus 3 with either tool.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Does the Nexus REST API return all assets in one response?<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">No. <code>\/service\/rest\/v1\/assets<\/code> and <code>\/service\/rest\/v1\/search\/assets<\/code> return results one page at a time, with a <code>continuationToken<\/code>. Pass the token back in the next request until it is <code>null<\/code>.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Related tutorials<\/h2>\n\n\n\n<ul class=\"wp-block-list\">\n<li><a href=\"https:\/\/www.devopsschool.com\/blog\/category\/devops\/artifact-repositories\/\">More Artifact Repositories tutorials<\/a><\/li>\n\n\n<li><a href=\"https:\/\/www.devopsschool.com\/blog\/top-50-nexus-interview-questions-and-answers\/\">Top 50 Sonatype Nexus interview questions and answers<\/a><\/li>\n\n\n<li><a href=\"https:\/\/www.devopsschool.com\/blog\/what-is-sonatype-and-use-cases-of-sonatype\/\">What is Sonatype and use cases of Sonatype?<\/a><\/li>\n<\/ul>\n","protected":false},"excerpt":{"rendered":"<p>With curl you can download a file from Sonatype Nexus Repository 3 in two ways. If you know the exact path, request \/repository\/&lt;repo&gt;\/&lt;path&gt;. If you only know&#8230; <\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_joinchat":[],"footnotes":""},"categories":[26142],"tags":[26213],"class_list":["post-31672","post","type-post","status-publish","format-standard","hentry","category-artifact-repositories","tag-sonatype-nexus-repository"],"_links":{"self":[{"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/posts\/31672","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/comments?post=31672"}],"version-history":[{"count":2,"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/posts\/31672\/revisions"}],"predecessor-version":[{"id":80554,"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/posts\/31672\/revisions\/80554"}],"wp:attachment":[{"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/media?parent=31672"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/categories?post=31672"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/tags?post=31672"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}