We can install the Microsoft SQL Server on ubuntu using the repository. You can also check the SQL express version and install the client on ubuntu. Let’s see, How to install the MSSQL server on Ubuntu.
How To Install Microsoft SQL Server On Ubuntu 20.04/19.10:
It’s a good idea to keep the system update. if you want to have the latest packages and version then run the below commands to update them.
sudo apt update sudo apt upgrade sudo reboot
- When you’re done with the above commands. we have to import public repository GPG key on the ubuntu.
sudo wget -qO- https://packages.microsoft.com/keys/microsoft.asc | sudo apt-key add -
2. You need to add the Microsoft SQL Server 2019 repository using the below commands.
sudo add-apt-repository "$(wget -qO- https://packages.microsoft.com/config/ubuntu/18.04/mssql-server-2019.list)"
3. Once you have added the repository. we will install the MSSQL server using the below command.
sudo apt update sudo apt install mssql-server -y
4. When the package installation finished, run the below command and follow the steps to set the SA password then select your edition version.
sudo /opt/mssql/bin/mssql-conf setup
5. Now, you have to select the edition version and I have selected the free version using 3 number and enter.
We have selected our edition and now it will ask you to accept the terms and conditions. Press “y” then enter.
Set your administrative password minimum digits should be 8 or more. This will start the configuration setup.
We’ve successfully installed the MSSQL server on the ubuntu machine. you need to check the service is running or not using the below commands.
systemctl status mssql-server --no-pager
6. If you want to check the listening port of the MSSQL server, use the below command.
sudo netstat -tnlp | grep sqlservr
When you want to access this server remotely, you have to open the default port 1433 in the firewall rules.
firewall-cmd --permanent -add-port=1433/tcp firewall-cmd --reload
Using the IPTables: Run the following commands.
iptables -A INPUT -p tcp -dport 1433 -j ACCEPT iptables-save > /etc/sysconfig/iptables
Install MSSQL Command-line Tool:
Now we need to install the command-line tool to access the database locally. This will install the SQL client on ubuntu.
- you have to import the public key repository by running the command.
curl https://packages.microsoft.com/keys/microsoft.asc | sudo apt-key add -
2. Install the Microsoft Ubuntu repository.
curl https://packages.microsoft.com/config/ubuntu/18.04/prod.list | sudo tee /etc/apt/sources.list.d/msprod.list
3. Update the source files and install the ODBC driver using the following commands.
sudo apt-get update sudo apt-get install mssql-tools unixodbc-dev
If you get the below errors like “no mssql-tools on ubuntu” while running the above commands,
Ubuntu 20.04 is not supported for the MSSQL server 2019 at this moment. you can install this version on Ubuntu 16.04/18.04.
4. Suppose, you have installed on Ubuntu 18.04 then you have run the commands from step 3. Now we need to access it using the below command.
sqlcmd -S localhost -U SA -P '<YourPassword>'
If the above command is successful, you will see the sqlcmd command prompt.
5. Check the SQL Express version using the select @@version command from the SQL command prompt.