Create Ruby apps using SQL Server on Ubuntu
In this section, you will get SQL Server 2017 running on Ubuntu. After that you will install the necessary dependencies to create Ruby apps with SQL Server.
Step 1.1 Install SQL Server
Note: To ensure optimal performance of SQL Server, your machine should have at least 4 GB of memory. If you need to get Ubuntu, check out the Ubuntu Downloads website.
-
Register the Microsoft Linux repositories and add their keys
curl https://packages.microsoft.com/keys/microsoft.asc | sudo apt-key add - curl https://packages.microsoft.com/config/ubuntu/16.04/mssql-server.list | sudo tee /etc/apt/sources.list.d/mssql-server.list
-
Install SQL Server
sudo apt-get update sudo apt-get install mssql-server
Reading package lists... Done Building dependency tree Reading state information... Done The following NEW packages will be installed: mssql-server ... Unpacking mssql-server ... Setting up mssql-server ...
-
Setup your SQL Server
sudo /opt/mssql/bin/mssql-conf setup
Microsoft(R) SQL Server(R) Setup To abort setup at anytime, press Ctrl-C. The license terms for this product can be downloaded from http://go.microsoft.com/fwlink/?LinkId=746388 and found in /usr/share/doc/mssql-server/LICENSE.TXT. Do you accept the license terms? If so, please type YES: Please enter a password for the system administrator (SA) account: Please confirm the password for the system administrator (SA) account:
You now have SQL Server running locally on your Ubuntu machine! Check out the next section to continue installing prerequisites.
Step 1.2 Install prerequisites for Ruby
Use the commands below to install prerequisites.
sudo apt-get update
sudo apt-get install autoconf bison build-essential libssl-dev libyaml-dev libreadline6-dev zlib1g-dev libncurses5-dev libffi-dev libgdbm3 libgdbm-dev
sudo apt-get install git
Step 1.3 Install rbenv and ruby-build
If you already have rbenv and ruby-build installed on your machine, skip this step. Use the following commands to install prerequisites for Ruby.
cd
git clone https://github.com/rbenv/rbenv.git ~/.rbenv
echo 'export PATH="$HOME/.rbenv/bin:$PATH"' >> ~/.bashrc
echo 'eval "$(rbenv init -)"' >> ~/.bashrc
exec $SHELL
git clone https://github.com/rbenv/ruby-build.git ~/.rbenv/plugins/ruby-build
echo 'export PATH="$HOME/.rbenv/plugins/ruby-build/bin:$PATH"' >> ~/.bashrc
exec $SHELL
Step 1.4 Install Ruby
Use the commands below to install Ruby using rbenv and check the version.
rbenv install 2.4.0
rbenv global 2.4.0
ruby -v
ruby 2.4.0p0 (2016-12-24 revision 57164) [x86_64-linux-gnu]
Step 1.5 Install FreeTDS
FreeTDS is a driver that enables you to connect to SQL Server. It is a prerequisite for the connector you’ll get later in the tutorial to connect to SQL Server. Run the following commands to install FreeTDS:
wget ftp://ftp.freetds.org/pub/freetds/stable/freetds-1.00.27.tar.gz
tar -xzf freetds-1.00.27.tar.gz
cd freetds-1.00.27
./configure --prefix=/usr/local --with-tdsver=7.3
make
make install
You have successfully installed Ruby on your Ubuntu machine. You now have everything you need to start writing your Ruby apps with SQL Server!
Have Questions?
Happy to help! You can find us on GitHub, MSDN Forums, and StackOverflow. We also monitor the #SQLServerDev hashtag on Twitter.