00:00:00

Share Your Feedback 🏝️

Post | Ruby + Gem + Jekyll on Ubuntu 22.04

Post | Ruby + Gem + Jekyll on Ubuntu 22.04

MinWoo(Daniel) Park | Tech Blog

Read more
Previous: MultiModal | Meta AI - Chameleon Next: Post | Nginx + SSL + Flask on Ubuntu 22.04

Post | Ruby + Gem + Jekyll on Ubuntu 22.04

  • Related Project: Private
  • Category: Paper Review
  • Date: 2024-05-08

Installing command Ruby + GEM + Jekyll on Ubuntu 22.04 with RVM

Q: Why did you build it manually when GitHub builds automatically?
GitHub builds take a long time depending on the number of posts, and debugging is very difficult as changes are not reflected in real-time.

Check Jekyll installation, RubyGems.org

Command summary


  sudo apt-get update -y && sudo apt-get upgrade -y
  sudo apt-get install -y libssl-dev libreadline-dev zlib1g-dev
  rvm install 2.7.3
  sudo apt update
  sudo apt install git curl libssl-dev libreadline-dev zlib1g-dev autoconf bison build-essential libyaml-dev libreadline-dev libncurses5-dev libffi-dev libgdbm-dev
  curl -fsSL https://github.com/rbenv/rbenv-installer/raw/HEAD/bin/rbenv-installer | bash
  echo 'export PATH="$HOME/.rbenv/bin:$PATH"' >> ~/.bashrc
  echo 'eval "$(rbenv init -)"' >> ~/.bashrc
  source ~/.bashrc
  type rbenv
  rbenv install -l            ########### Select proper version for you
  rbenv install 3.2.4
  rbenv global 3.2.4
  ruby -v
  echo "gem: --no-document" > ~/.gemrc
  gem install bundler
  gem update --system 3.5.11
  gem env home
  gem install rails -v 7.0.4
  gem search '^rails$' --all
  rbenv rehash
  rails -v                    ########### You can change rails version, but recommend to try default version
  gem update
  gem install jekyll bundler  ########### Install jekyll bundler
  jekyll -v                   ########### Check jekyll version



1 Understanding Gem, Ruby, and Jekyll

1.1 Ruby

Ruby is a dynamic, open-source programming language known for its simplicity and productivity. It features an elegant syntax that is easy to read and write, making it a popular choice for web development, scripting, and more. Ruby is a dynamic, open-source programming language with a focus on simplicity and productivity.

1.2 Gems

Gems are packaged libraries or applications written in Ruby. They allow developers to share and reuse code efficiently. Gems can be easily installed and managed using the gem command-line tool. A typical gem includes:

  • A name and version
  • Executable code
  • Documentation
  • Dependencies

1.3 Jekyll

Jekyll is a simple, blog-aware, static site generator. It transforms plain text into static websites and blogs. Jekyll processes content written in Markdown or Liquid templates and generates a complete, static site that can be served by any web server. Key features of Jekyll include:

  • Static Site Generation: Converts text files into static HTML pages.
  • Markdown Support: Uses Markdown for content creation.
  • Liquid Templating: Supports Liquid templating for dynamic content.
  • Easy Deployment: Integrates well with GitHub Pages for easy hosting.

Example Workflow with Jekyll

  1. Install Jekyll: Install Jekyll using the following command:
    gem install jekyll
    
  2. Create a New Site: Create a new Jekyll site using:
    jekyll new my-awesome-site
    cd my-awesome-site
    
  3. Build the Site: Build the site and serve it locally:
    bundle exec jekyll serve
    
  4. View the Site: Open your browser and navigate to http://localhost:4000 to see your site.



2 Build site

This code has been modified to address initial build errors in ubuntu 22.04, but it may vary depending on your environment. Please carefully review the logs and make necessary adjustments. (2024-06-18)

2.1 Installation

# Install build tools for your system
sudo apt-get update
sudo apt-get install build-essential libssl-dev libreadline-dev zlib1g-dev

# Attempt to install sass-embedded manually
gem install sassc
gem install sass-embedded -v '1.62.0'

# Update Bundler to the latest version
gem install bundler

# Install missing gems specified in the Gemfile
bundle install

# Clean the Bundler environment to remove unused gems
bundle clean --force

# Reinstall the gems specified in the Gemfile
bundle install

# Build the Jekyll site
jekyll build

# Serve port default: 4000
jekyll serve

# Specific port serving
jekyll serve --port 4001

If the build fails, check the logs for any template errors or review the _config.yml file, then try building again.

2.2 Build and Serve Guidelines

To clean build, del _sites and jekyll serve

  1. Build Process: When you build, the system considers custom CSS and other basic assets, compiling them into the _site directory.
  2. Pre-Build Cleanup: Before building, it’s a good practice to clear the browser cache and remove the _site directory. This ensures that the build results are accurate and ready for serving. Overlapping CSS files can cause errors, so be mindful of their priorities.
  3. Serving the Site: The serve command builds and serves the site, but it can be affected by existing content in the _site directory or the browser cache. Pay close attention to the HTML, CSS, and build order to avoid issues.
     rm Gemfile.lock
     bundle install
     jekyll build
     jekyll serve
    
  4. Tips
    • After adding "plugins": ["livereload"], you can use jekyll serve --reload instead of jekyll serve.
    • Pay attention to the CSS loading order to ensure proper application. Especially, make sure to distinguish between JS and CSS files in include and assets.
    • Adjust the CSS loading order mainly in head.html and post.html or body in jekyll template.
    • Check the delimiters carefully to apply correctly, especially config.yml in jekyll template.


You can visit GitBlog, built with this guide. Happy Coding!

How to Use Systemctl to Manage a Flask Application with a Virtual Environment

TL;DR

# Step 1: Create a New Script
nano /home/daniel/start_label_app.sh

# Add the following content to the script:
#!/bin/bash
source /home/daniel/Public/venv/flask/bin/activate
pip install -r /home/daniel/Desktop/git_ram/gorani-dev/private/label-app/label-flask-main/requirements.txt
python /home/daniel/Desktop/git_ram/gorani-dev/private/label-app/label-flask-main/label_app.py

# Save and exit the text editor, then make the script executable:
chmod +x /home/daniel/start_label_app.sh

# Step 2: Modify the Service File
sudo nano /etc/systemd/system/label_app.service

# Replace the content with the following:
[Service]
User=daniel
Group=www-data
WorkingDirectory=/home/daniel/Desktop/git_ram/gorani-dev/private/label-app/label-flask-main
ExecStart=/bin/bash /home/daniel/start_label_app.sh
Restart=always
StandardOutput=file:/var/log/label_app_output.log
StandardError=file:/var/log/label_app_error.log

# Save the service file and exit the text editor.

# Step 3: Apply the Service File and Restart the Service
sudo systemctl daemon-reload
sudo systemctl restart label_app.service

# Step 4: Check the Logs and Service Status
sudo systemctl status label_app.service
cat /var/log/label_app_error.log

# Troubleshooting
# If issues persist, check error logs and ensure paths are correct. Adjust the script as needed.

systemctl is a command-line utility that allows you to manage systemd services on Linux-based operating systems. This tool is commonly used to start, stop, restart, enable, and disable services. In this guide, we’ll walk through the process of setting up a systemd service to manage a Flask application that runs within a Python virtual environment.

Step 1: Create a New Script

First, we need to create a script that will activate the virtual environment and start the Flask application. This script will also ensure that the necessary Python dependencies are installed.

  1. Open a terminal and create a new script file:
    nano /home/daniel/start_label_app.sh
    

    Add the following content to the script:

    #!/bin/bash
    source /home/daniel/Public/venv/flask/bin/activate
    python /home/daniel/Desktop/git_ram/gorani-dev/private/label-app/label-flask-main/label_app.py
    

    This script does three main things

    • Activates the Python virtual environment (venv).
    • Installs any required packages listed in the requirements.txt file.
    • Starts the Flask application.
  2. Save the script and exit the text editor.

  3. Make the script executable by running:
    chmod +x /home/daniel/start_label_app.sh
    

Step 2: Modify the Service File

Next, we need to modify the systemd service file to execute our new script.

  1. Open or create the systemd service file for your Flask application:
    sudo nano /etc/systemd/system/label_app.service
    
  2. Replace the content with the following:

    [Service]
    User=daniel
    Group=www-data
    WorkingDirectory=/home/daniel/Desktop/git_ram/gorani-dev/private/label-app/label-flask-main
    ExecStart=/bin/bash /home/daniel/start_label_app.sh
    Restart=always
    StandardOutput=file:/var/log/label_app_output.log
    StandardError=file:/var/log/label_app_error.log
    

    Explanation:

    • User and Group: Specifies the user and group under which the service will run.
    • WorkingDirectory: The directory where the Flask application is located.
    • ExecStart: Specifies the command that systemd will run when starting the service. Here, we point it to our script.
    • Restart=always: Ensures the service will automatically restart if it fails.
    • StandardOutput and StandardError: Log files where the service’s output and errors will be recorded.
  3. Save the service file and exit the text editor.

Step 3: Apply the Service File and Restart the Service

After modifying the service file, you need to reload the systemd manager configuration to apply the changes, and then restart the service.

  1. Reload the systemd configuration:
    sudo systemctl daemon-reload
    
  2. Restart the service:
    sudo systemctl restart label_app.service
    

Step 4: Check the Logs and Service Status

Finally, check to make sure the service is running correctly and review the logs for any potential issues.

  1. Check the service status:
    sudo systemctl status label_app.service
    

    This command will provide details about whether the service is running or if there were any issues during startup.

  2. Review the log files for any errors:
    cat /var/log/label_app_error.log
    

    This command will show you the error log, where any issues related to the Flask application startup will be recorded.

Troubleshooting

If you still encounter issues, the error logs should give you specific clues about what went wrong. Common issues might include incorrect paths, missing dependencies, or syntax errors in the script.

By following these steps, you can set up a robust systemd service to manage your Flask application, ensuring it runs smoothly and restarts automatically if needed.

Previous: MultiModal | Meta AI - Chameleon Next: Post | Nginx + SSL + Flask on Ubuntu 22.04

post contain ""

    No matching posts found containing ""