{"id":2025,"date":"2024-11-05T13:33:00","date_gmt":"2024-11-05T06:33:00","guid":{"rendered":"https:\/\/tech2fun.net\/?p=2025"},"modified":"2024-11-05T14:42:11","modified_gmt":"2024-11-05T07:42:11","slug":"how-to-install-sonarqube-10-on-ubuntu-24","status":"publish","type":"post","link":"https:\/\/tech2fun.net\/?p=2025","title":{"rendered":"How to install SonarQube 10 on Ubuntu 24"},"content":{"rendered":"<p>This guide will help you install SonarQube on Ubuntu.<\/p>\n<blockquote>\n<p style=\"text-align: justify;\">The SonarQube or formerly Sonar is an open-source platform for static code analysis and code security. SonarQube integrates into your existing workflow and detects issues in your code to help you perform continuous code inspections of your projects.<\/p>\n<\/blockquote>\n<p><!--more--><\/p>\n<h2 id=\"prerequisites\">Prerequisites<\/h2>\n<ul>\n<li>A fresh Ubuntu 24.04 as standalone server (Physical or VM)<\/li>\n<li>A user with sudo privileges<\/li>\n<li>Java 17 installed (SonarQube requires a specific version of Java)<\/li>\n<\/ul>\n<p>For this tutorial, we have used virtual server with the configuration of <em><strong>2vCPU, 8GB RAM, 80GB SSD<\/strong><\/em>. It should have at least 2GB of RAM 1 CPU core and 30GB free space.<\/p>\n<div class=\"tasklabel\">\n<h2 id=\"taskp9hat_changeprofilep6__steps__1\" class=\"sectiontitle tasklabel bx--type-expressive-heading-04\">Procedure<\/h2>\n<\/div>\n<h3>Step 1 &#8211; System update and install Java<\/h3>\n<h3><\/h3>\n<pre>$sudo apt update\n$sudo apt upgrade -y\n$sudo apt install openjdk-17-jdk -y<\/pre>\n<pre>$java -version<\/pre>\n<h3>Step 2 &#8211; Install and Configure PostgreSQL<\/h3>\n<p>I install PostgreSQL 15 as requirement in this demo. You can choose another database (Oracle, Microsoft SQL), please check compatible version detail <a href=\"https:\/\/docs.sonarsource.com\/sonarqube\/latest\/setup-and-upgrade\/installation-requirements\/database-requirements\/\">here<\/a><\/p>\n<p>Install certificate<\/p>\n<pre>sudo apt install curl ca-certificates\nsudo install -d \/usr\/share\/postgresql-common\/pgdg\nsudo curl -o \/usr\/share\/postgresql-common\/pgdg\/apt.postgresql.org.asc --fail https:\/\/www.postgresql.org\/media\/keys\/ACCC4CF8.asc\nsudo sh -c 'echo \"deb [signed-by=\/usr\/share\/postgresql-common\/pgdg\/apt.postgresql.org.asc] https:\/\/apt.postgresql.org\/pub\/repos\/apt $(lsb_release -cs)-pgdg main\" &gt; \/etc\/apt\/sources.list.d\/pgdg.list'<\/pre>\n<p>Run update and install PostgreSQL 15<\/p>\n<pre>sudo apt update\nsudo apt install postgresql-15 -y<\/pre>\n<p>Lets configure PostgreSQL as following<br \/>\n&#8211; Switch to postgres user, create database and database user<\/p>\n<pre>sudo -i -u postgres<\/pre>\n<pre>createuser sonar\ncreatedb sonar -O sonar\npsql<\/pre>\n<pre>ALTER USER sonar WITH ENCRYPTED PASSWORD 'your_password';\n\\q\nexit<\/pre>\n<h3>Step 3 &#8211; Install and Configure SonarQube<\/h3>\n<p>Download and extract the SonarQube package<\/p>\n<pre>wget https:\/\/binaries.sonarsource.com\/Distribution\/sonarqube\/sonarqube-10.6.0.92116.zip<\/pre>\n<pre>unzip sonarqube-10.6.0.92116.zip\nsudo mv sonarqube-10.6.0.92116.zip \/opt\/sonarqube<\/pre>\n<p>Create SonarQube user and change permission<\/p>\n<pre>sudo adduser --system --no-create-home --group --disabled-login sonarqube<\/pre>\n<pre>sudo chown -R sonarqube:sonarqube \/opt\/sonarqube<\/pre>\n<p>Edit SonarQube config file<br \/>\n&#8211; Uncomment and set username, password, jdbc.url as below in the sonar.properties file<\/p>\n<pre>sudo nano \/opt\/sonarqube\/conf\/sonar.properties<\/pre>\n<pre>sonar.jdbc.username=sonar\nsonar.jdbc.password=your_password\nsonar.jdbc.url=jdbc:postgresql:\/\/localhost\/sonar<\/pre>\n<h3>Step 4 &#8211; Configure a service,\u00a0 filesystem limit and Firewall rules<\/h3>\n<ol>\n<li>Create service file for SonarQube<\/li>\n<\/ol>\n<pre><strong>#Create a service file<\/strong>\nsudo nano \/etc\/systemd\/system\/sonarqube.service<\/pre>\n<pre><strong>#Add the following contents<\/strong>\n[Unit]\nDescription=SonarQube service\nAfter=syslog.target network.target\n\n[Service]\nType=forking\n\nExecStart=\/opt\/sonarqube\/bin\/linux-x86-64\/sonar.sh start\nExecStop=\/opt\/sonarqube\/bin\/linux-x86-64\/sonar.sh stop\n\nUser=sonarqube\nGroup=sonarqube\nRestart=always\n\nLimitNOFILE=65536\nLimitNPROC=4096\n\n[Install]\nWantedBy=multi-user.target<\/pre>\n<pre><strong>#Reload services<\/strong>\nsudo systemctl daemon-reload\nsudo systemctl start sonarqube\nsudo systemctl enable sonarqube<\/pre>\n<p>2. Check and set system limits<\/p>\n<pre><strong>#To inscrease system limits, open below file<\/strong>\nsudo nano \/etc\/security\/limits.conf<\/pre>\n<pre><strong>#Add below lines to file<\/strong>\nsonarqube \u00a0 - \u00a0 nofile \u00a0 65536\nsonarqube \u00a0 - \u00a0 nproc \u00a0 \u00a04096<\/pre>\n<pre><strong>#Open sysctl.conf file to change virtual memory limits<\/strong>\nsudo nano \/etc\/sysctl.conf<\/pre>\n<pre><strong>#Add following line<\/strong>\nvm.max_map_count=262144<\/pre>\n<pre><strong>#Apply system changes<\/strong>\nsudo sysctl -p<\/pre>\n<p>3. Config firewall rules<\/p>\n<pre><strong>#Run following commands<\/strong>\nufw allow 9000\/tcp\nufw allow 80\/tcp\nufw allow 443\/tcp\nufw reload<\/pre>\n<h3>Step 5 &#8211; Install Nginx and Config SSL Certificate<\/h3>\n<ol class=\"steps bx--list--ordered--temporary list--ordered--indented\">\n<li class=\"step stepexpand bx--list__item\" data-hd-product=\"li_0CU\"><span class=\"cmd\">Install Nginx.<\/span>\n<pre>sudo apt install nginx -y<\/pre>\n<\/li>\n<li class=\"step stepexpand bx--list__item\" data-hd-product=\"li_0CU\"><span class=\"cmd\">Create Nginx config file for SonarQube<br \/>\n<\/span><\/p>\n<pre>sudo nano \/etc\/nginx\/sites-available\/sonarqube.example.com<\/pre>\n<pre><strong>#Add following content to the <em>sonarqube.example.com<\/em> file<\/strong>\nserver {\n\u00a0 \u00a0 listen 80;\n\u00a0 \u00a0 server_name sonarqube.example.com;\n\n\u00a0 \u00a0 access_log \/var\/log\/nginx\/sonarqube.access.log;\n\u00a0 \u00a0 error_log \/var\/log\/nginx\/sonarqube.error.log;\n\n\u00a0 \u00a0 location \/ {\n\u00a0 \u00a0 \u00a0 \u00a0 proxy_pass http:\/\/localhost:9000;\n\u00a0 \u00a0 \u00a0 \u00a0 proxy_set_header Host $host;\n\u00a0 \u00a0 \u00a0 \u00a0 proxy_set_header X-Real-IP $remote_addr;\n\u00a0 \u00a0 \u00a0 \u00a0 proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;\n\u00a0 \u00a0 \u00a0 \u00a0 proxy_set_header X-Forwarded-Proto $scheme;\n\u00a0 \u00a0 }\n}<\/pre>\n<\/li>\n<li class=\"step stepexpand bx--list__item\" data-hd-product=\"li_0CU\"><span class=\"cmd\">Check and Restart Nginx service<br \/>\n<\/span><\/p>\n<pre><strong>#Link the config file to enable when start Nginx<\/strong>\nsudo ln -s \/etc\/nginx\/sites-available\/sonarqube.example.com \/etc\/nginx\/sites-enabled\/<\/pre>\n<pre>sudo nginx -t\nsudo systemctl restart nginx<\/pre>\n<\/li>\n<li class=\"step stepexpand bx--list__item\" data-hd-product=\"li_0CU\"><span class=\"cmd\">Configure SSL for Nginx domain.<\/span><\/li>\n<\/ol>\n<pre>sudo apt install certbot python3-certbot-nginx -y<\/pre>\n<pre>sudo certbot --nginx -d sonarqube.example.com<\/pre>\n<h2>Final step &#8211; Access SonarQube site.<\/h2>\n<p>Open web browser and access the link <strong>http (https):\/\/IP_Address_Or_Domain:9000<\/strong><\/p>\n<p>References: <a title=\"AIX Installation Quick Start Guide\" href=\"https:\/\/tech2fun.net\/index.php\/2023\/03\/01\/aix-installation-quick-start-guide\/\" rel=\"bookmark\">AIX Installation Quick Start Guide<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>This guide will help you install SonarQube on Ubuntu. The SonarQube or formerly Sonar is an open-source platform for static code analysis and code security. SonarQube integrates into your existing workflow and detects issues in your code to help you perform continuous code inspections of your projects.<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[84,129],"tags":[132,136,135,137],"class_list":["post-2025","post","type-post","status-publish","format-standard","hentry","category-devops","category-ubuntu","tag-aix","tag-hmc-profile","tag-ibm-hmc","tag-partition-profile"],"_links":{"self":[{"href":"https:\/\/tech2fun.net\/index.php?rest_route=\/wp\/v2\/posts\/2025","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/tech2fun.net\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/tech2fun.net\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/tech2fun.net\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/tech2fun.net\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=2025"}],"version-history":[{"count":9,"href":"https:\/\/tech2fun.net\/index.php?rest_route=\/wp\/v2\/posts\/2025\/revisions"}],"predecessor-version":[{"id":2042,"href":"https:\/\/tech2fun.net\/index.php?rest_route=\/wp\/v2\/posts\/2025\/revisions\/2042"}],"wp:attachment":[{"href":"https:\/\/tech2fun.net\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=2025"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/tech2fun.net\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=2025"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/tech2fun.net\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=2025"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}