From a Jekyll blog to Ruby (Basics)
Jan 3rd, 2022For someone who works primarily around Python & JavaScript (and recently started iOS dev with Obj-C and Swift), setting up this blog with Jekyll is my first experience to interact with everything Ruby. I had some struggles during development around understanding some terminologies and setting up the environment, but I found comparing them with what I know in Python and JavaScript works well for me.
Ruby, Gems, and RubyGems ๐
Ruby is โฆ ๐
A dynamic, open source programming lanaguage with a focus on simplicity and productivity. (source)
This should be fairly straightforward, but I got interested in how the official websites describe the languages in 1 sentence. So here we go:
Python is โฆ ๐
a programming language that lets you work quickly and integrate systems more effectively. (source)
JavaScript is โฆ ๐ธ
the worldโs most popular programming language.
the programming language of the Web.
easy to learn. (source)
And into the iOS realm. Objective-C is โฆ ๐ป
the primary programming language you use when writing software for OS X and iOS. itโs a superset of the C programming language and provides object-oriented capabilities and a dynamic runtime. (source)
Finally, Swift is โฆ ๐จ
a powerful and intuitive programming language for iOS, iPadOS, macOS, tvOS and watchOS. (source)
And back to the scheduled programmeโฆ
For programs written in these languages, they can invoke some functionalities that are provided by packages (or libraries).
๐ In the world of Python, we call them Packages or Libraries. The tool we often use for managing these packages/libraries is PyPi. To install and manage them, we often use pip install
. The configuration file requirement.txt is also commonly used to conveniently install the specified package with the specified version.
๐ธ Relatively, in the world of JavaScript, we also use Packages/Libraries to provide some additional functions to our program. The tool we use for managing them changes to NPM or Yarn and we use npm install
or yarn add
for installing packages. The configuration file package.json acts similiar to requirement.txt in terms of specifying the versions of the depencies (and with a lot more other responsibilities).
๐ป For Cocoa applications, the tools and config file we use change to Carthage and Cartfile. The command we use becomes carthage update
.
๐ And now back to the world of Ruby, a Gem is just another saying for a package and library and RubyGem is a tool to install, create, manage and load these packages in the Ruby envrionment (source). A Gemfile is similiar to requirement.txt, package.json and Carfile, listing the gems used by the progrem. To install a gem, use gem install
For Jekyll specifically, a Bundler (also a gem) is used to install all gems in the Gemfile by using bundle install
.
Gotchas when working with RubyGems ๐
-
To install a gem without a Bundler, use
gem install <gemName>
. However, unlike NPM which provides both global install option withnpm install -g
and local install option withnpm install
, gem installation is always system wide, and the package is always available for any projects within the system. -
When using
--user-install
option withgem install
, RubyGems will install the gems to a directory inside your home directory. For programs installed there to be available, you need to add the destination to your PATH environment variable